使用reportviwer中的rdlc导出pdf时设置pdf的密码 [英] set Password for pdf while exporting the pdf using rdlc from reportviwer

查看:102
本文介绍了使用reportviwer中的rdlc导出pdf时设置pdf的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

请帮助我,



用报告查看器生成pdf报告如何设置密码为pdf。



i通过使用类型pdf后面的代码来做,但我想在导出到pdf点击那个时候我需要为生成设置密码pdf文件。



我做了什么我把代码粘贴在这里。



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;
                //Render the report
                renderedBytes = rvLMSReport.LocalReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
                //Response.Clear();
                //Response.ContentType = mimeType;
                //string path = System.IO.Path.GetTempPath();
                //filePath = System.IO.Path.Combine(path, reportname + "." + fileNameExtension);
                //Response.AddHeader("content-disposition", "attachment; filename=" + reportname + "." + fileNameExtension);
                //Response.BinaryWrite(renderedBytes);
                // Response.End();
                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();
                        //Response.End();
                    }
                }

            }
            catch (Exception ex)
            {

            }

推荐答案

访问这里..



http://stackoverflow.com/questions/370571/password-protected-pdf-using-c-sharp [<一个href =http://stackoverflow.com/questions/370571/password-protected-pdf-using-c-sharptarget =_ blanktitle =New Window> ^ ]
visit here..

http://stackoverflow.com/questions/370571/password-protected-pdf-using-c-sharp[^]


这篇关于使用reportviwer中的rdlc导出pdf时设置pdf的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆