简体   繁体   中英

PDF pages are blank after setting password for existing PDF using iTextSharp

I am using iTextSharp (C#) for setting password for a existing PDF. I am able to set the password for the existing pdf but while opening the pdf (after saving) all the pages are completely blank. Please help me with this.

Code Used:

private void securePDFFile(string InputFile, string OutputFile)
    {

        using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            PdfReader reader = new PdfReader(input);
            using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
            {

                PdfEncryptor.Encrypt(reader, output, true, null, "secret", PdfWriter.AllowScreenReaders);
            }
        }
    }

Regards, Balaji

I just found quick thing in the Itext sharp documentation that only files that have been created with Itext sharp( the existing pdf's that have been created with Itest Shapr only) can be secured using Itext sharp, other files can't be secured and that's reason why its blank. The best alternative would be PDF sharp which secures all files.

Regards, Balaji

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM