0

I am using following code to generate PDF's. I want to password protect the PDF.

How to Password Protect PDF's in iTextSharp?

document = new Document(PageSize.A4, 10, 10, 25, 25);
output = new MemoryStream();
writer = PdfWriter.GetInstance(document, output);

document.Open();    
document.Add(OuterTable);    
document.Close();    

System.IO.File.WriteAllBytes(Server.MapPath("~/PDFs/" + name.ToString() + ".pdf"), output.ToArray());
tereško
  • 58,060
  • 25
  • 98
  • 150
Anup
  • 9,396
  • 16
  • 74
  • 138

1 Answers1

0

You can use the PdfEncryptor. The userPassword arg will set a password on it. http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfEncryptor.html

Sdyess
  • 340
  • 1
  • 8
  • I am confused about the first parameter for the method `PdfEncryptor.Encrypt()`. What should i pass to it? – Anup Feb 24 '15 at 09:20
  • Here's an example of someone using it. http://stackoverflow.com/questions/6586346/itextsharp-password-protected-pdf – Sdyess Feb 24 '15 at 09:21