2012-09-17 80 views
1

我創建PDF動態。因此,同時創建自己,我需要用密碼保護它。 我m使用asp.net,c#和pdf itextsharp。如何使用itextsharp創建密碼保護的pdf?

這是使用我的代碼

(文獻DOC =新的文檔(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"); 
         }  

謝謝..

+0

可能重複的[iTextSharp密碼保護PDF](http://stackoverflow.com/questions/6586346/itextsharp-password-protected-pdf) – sloth

回答