我动态创建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");
}
谢谢..