I am trying to take an already made pdf file, and password protect it. The code is successfully adding the password protection, but all the pages in the resulting pdf are blank. The issue is not pdf file specific, any pdf file I use has the same result.
I am using PDFSharp 1.50.4740-beta5 (I've tried a couple of the previous versions but they have the same issue. I can't use anything before 1.5 because prior versions don't support Adobe 6.
What's odd is that before I had to upgrade, I could do this without issue in PDFSharp 1.32. Can anyone assist, or point me in the right direction?
Example PDF that I attempted with: http://www.africau.edu/images/default/sample.pdf
The code is from the sample provided here: http://www.pdfsharp.net/wiki/ProtectDocument-sample.ashx?HL=password
// Open an existing document. Providing an unrequired password is ignored.
PdfDocument document = PdfReader.Open(@"filelocation1", "sometext");
PdfSecuritySettings securitySettings = document.SecuritySettings;
securitySettings.UserPassword = "test";
securitySettings.OwnerPassword = "test";
securitySettings.PermitAccessibilityExtractContent = false;
securitySettings.PermitAnnotations = false;
securitySettings.PermitAssembleDocument = false;
securitySettings.PermitExtractContent = false;
securitySettings.PermitFormsFill = true;
securitySettings.PermitFullQualityPrint = false;
securitySettings.PermitModifyDocument = true;
securitySettings.PermitPrint = false;
// Setting one of the passwords automatically sets the security level to
// PdfDocumentSecurityLevel.Encrypted128Bit.
//securitySettings.UserPassword = "test";
// Don't use 40 bit encryption unless needed for compatibility reasons
//securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted40Bit;
// Save the document...
document.Save(@"filelocation2");
document.Close();
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…