【问题标题】:How to create password protected pdf using itextsharp?如何使用 itextsharp 创建受密码保护的 pdf?
【发布时间】:2012-09-09 09:02:38
【问题描述】:

我正在动态创建 pdf。所以在创建自身时我需要用密码保护它。 我正在使用 asp.net、c# 和 pdf itextsharp。

这是我的代码

使用 (Document doc = new Document(PageSize.A4,0f,0f,0f,0f)) {

            string path = Server.MapPath("Pages");

            FileStream pdffile= new FileStream(path+"/Pdf/tes.pdf", FileMode.Create);
            PdfWriter writer=PdfWriter.GetInstance(doc,pdffile);
            doc.Open();
            var titlefont = FontFactory.GetFont("Arial", 16, Font.BOLD);   
            doc.Add(new Paragraph("My Pdf",titlefont));
            doc.Close(); 

            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=tes.pdf"); 
            Response.TransmitFile(path+"/Pdf/tes.pdf");                  
            Response.Flush();
            File.Delete(path + "/Pdf/tes.pdf");
                        }     

谢谢..

【问题讨论】:

标签: asp.net


【解决方案1】:

我搜索了其他主题,这似乎对这个人有用:

https://stackoverflow.com/a/6586551/1648976

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 2013-07-14
    • 2011-02-02
    • 2011-12-23
    • 2015-04-25
    • 1970-01-01
    • 2010-09-27
    相关资源
    最近更新 更多