0

I have created a pdf document and I need to protect the document with password.

  Document document = new Document(PageSize.A4.Rotate(), 10, 10, 10, 10);
        string pdfFilename = "dbtopdf.pdf";
        PdfWriter.GetInstance(document, new FileStream(pdfFilename, FileMode.Create));
        PdfPTable table = new PdfPTable(13);
        foreach (abccreation obj in list)
        {
       "Adding cell here... Not related"
        }
        document.Open();
        document.Add(table);
        document.Close();

Would like to ask is there a way to add a password into the document. So it will prompt user to enter password when the user is trying to read this. I have try to apply the to a pdf file with
pdf.SecuritySettings.UserPassword = "your password";

But somehow this document i created is not a pdf file so the same technic cannot be apply.

Chris
  • 124
  • 2
  • 12
  • What kind of document? Any or a specific format like `docx`? – NtFreX Jun 29 '17 at 06:43
  • 1
    Possible duplicate of [Password protected PDF using C#](https://stackoverflow.com/questions/370571/password-protected-pdf-using-c-sharp) – Tien Nguyen Ngoc Jun 29 '17 at 06:50
  • I do not know what is the format of the document i created. Or is there any method that allows me to convert the document into pdf format? – Chris Jun 29 '17 at 06:51
  • @TienNguyen Its different, those method can only apply to pdf file, Im having trouble to apply the password to my document which I do not know the format but its not a pdf. – Chris Jun 29 '17 at 06:53
  • *"I do not know what is the format of the document i created"* - Well, you use iTextSharp which is a library for PDF generation. Thus, I would assume you do create a PDF... – mkl Jun 29 '17 at 14:13

0 Answers0