Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

c# - PDFSharp returning blank pages when adding password

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@Viveladéraison solved my issue. I had to rollback a couple of builds to .4589 for the issue to be resolved.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...