【问题标题】:PDFSharp returning blank pages when adding password添加密码时PDFSharp返回空白页
【发布时间】:2018-02-11 02:00:59
【问题描述】:

我正在尝试获取已经制作的 pdf 文件,并使用密码保护它。该代码已成功添加密码保护,但生成的 pdf 中的所有页面都是空白的。问题不是特定于 pdf 文件,我使用的任何 pdf 文件都有相同的结果。

我正在使用 PDFSharp 1.50.4740-beta5(我尝试了几个以前的版本,但它们有同样的问题。我不能使用 1.5 之前的任何东西,因为以前的版本不支持 Adob​​e 6。

奇怪的是,在我必须升级之前,我可以在 PDFSharp 1.32 中毫无问题地做到这一点。任何人都可以提供帮助或指出正确的方向吗?

我尝试使用的示例 PDF:http://www.africau.edu/images/default/sample.pdf

代码来自此处提供的示例: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();

【问题讨论】:

  • 你能回滚到PDFSharp 1.32吗?
  • MCVE 将包含 PDF 文件。我是否正确理解 PDFsharp 1.32 无法打开文件,但您确定问题是 PDFsharp 1.50 的新问题?
  • 请尝试 PDFsharp 1.50 build 4589 或 build 4790。如果 build 4790 也失败,请提供包含 PDF 文件的 MCVE。
  • @mjwills 不,PDFSharp 1.32 不适用于 Adob​​e 6.x 之后的任何版本。
  • @Viveladéraison 我说它不是 PDF 特定的,所以我认为我不需要添加一个。任何随机的pdf都可以。但如果有帮助,我会提供一个示例。

标签: c# pdf pdfsharp


【解决方案1】:

@Viveladéraison 解决了我的问题。为了解决这个问题,我不得不将几个版本回滚到 .4589。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    相关资源
    最近更新 更多