Hi All,
Please help me,
when generating the report with pdf by report viewer how can i set password to pdf.
i did by using code behind with type pdf,but i want when export to pdf clicking that time i need to set password for generated pdf file.
what i did i paste the code here.
using Microsoft.Reporting.WebForms;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Text;
public void DownloadCertificate()
{
rvLMSReport.LocalReport.DataSources.Add(new ReportDataSource("CertificateofTraining", TraineeCertificat));
rvLMSReport.LocalReport.EnableExternalImages = true;
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<deviceinfo>" +
" <outputformat>PDF</outputformat>" +
" <pagewidth>21cm</pagewidth>" +
" <pageheight>29.7cm</pageheight>" +
"</deviceinfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = rvLMSReport.LocalReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
ReportEntityOperations objreportentity = new ReportEntityOperations();
objreportentity = TraineeCertificat.ToList().FirstOrDefault();
string CertificatePassword = GetUniqCode(8);
string Username = objreportentity.UserFullName;
string Coursename = objreportentity.CourseName;
string mailSub = "Your Status";
CompanyEmailSetting ObjComEmailSetting = new CompanyEmailSetting();
CompanyEmailSettingBLL objCompanyEmailSettingBLL = new CompanyEmailSettingBLL();
LanguageCompanyEmailSetting LangESettings = new LanguageCompanyEmailSetting();
LanguageCompanyEmailSettingBLL objLanguageCompanyEmailSettingBLL = new LanguageCompanyEmailSettingBLL();
ObjComEmailSetting = objCompanyEmailSettingBLL.SelectByCompanyId(objreportentity.CompanyId);
string mailBody = "You have get the Certificate Password " + "'" + CertificatePassword + "'" + " and with this you can open the Your Certificate'" + objreportentity.CourseName + "'Cresent'";
SendMail(objreportentity.TrainingRequestId, Guid.Empty, "Hello "+objreportentity.UserFullName, "Course", ObjComEmailSetting.EmailSMTPAddress, ObjComEmailSetting.EmailFromAddress, mailSub, mailBody, "kamalakar.kondi@bizbites.com", objreportentity.CompanyId, 1);
using (MemoryStream input = new MemoryStream(renderedBytes))
{
using (MemoryStream output = new MemoryStream())
{
PdfReader reader = new PdfReader(input);
PdfEncryptor.Encrypt(reader, output, true, CertificatePassword, CertificatePassword, PdfWriter.ALLOW_SCREENREADERS);
renderedBytes = output.ToArray();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + reportname + "." + fileNameExtension);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(renderedBytes);
Response.Flush();
Response.Close();
}
}
}
catch (Exception ex)
{
}