Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had created below code to protect pdf.
But I forgot to allow printing option.
Now printing option is disabled in all my protected pdfs.
Is there any solution to change the printing option to allow for all protected pdfs.
C#
using iTextSharp.text.pdf;

using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
      using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
      {
            PdfReader reader = new PdfReader(input);
            PdfEncryptor.Encrypt(reader, output, true, userpwd, masterpwd,PdfWriter.AllowScreenReaders);
       }
}
Posted
v2

1 solution

Hi!!!
And this is how to enable printing if you still want the pdf to be encrypted.
C#
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
writer.SetEncryption(null, encoding.GetBytes("12345678"), PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING, PdfWriter.STRENGTH40BITS);


refreance:http://weblog.kevinattard.com/2011/08/itextsharp-disable-pdf-printing.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900