【问题标题】:when filling a pdf document with pdfsharp, the filled form doesn't show the values unless the fields are clicked on使用 pdfsharp 填充 pdf 文档时,除非单击字段,否则填充的表单不会显示值
【发布时间】:2021-05-19 11:23:33
【问题描述】:

使用 pdfsharp (pdfsharpcore) 填充 pdf 文档时,除非单击字段,否则填充的表单不会在 acrobat 阅读器中显示值。

【问题讨论】:

    标签: .net pdf .net-core pdf-generation pdfsharp


    【解决方案1】:

    为了使值可见,我插入了。

    if (acroForms.Elements.ContainsKey("/NeedAppearances"))
        acroForms.Elements["/NeedAppearances"] = new PdfBoolean(true);
    else
        acroForms.Elements.Add("/NeedAppearances", new PdfBoolean(true));
    

    它有效。

    【讨论】:

    • 请注意,NeedAppearances 键和基础功能已在 PDF-2.0 (ISO 32000-2:2017) 中弃用。
    • 所以这不能解决填充值未出现在较新格式中的问题? @mkl
    • 只要您只需要处理 PDF-2 的要求,它就不会。不过,在许多情况下,PDF-1 很可能在很长一段时间内仍然具有相关性。
    • 感谢 cmets 的帮助。 pdf-2 中是否存在与 NeedAppearances 标志相同的功能?
    • 不,没有等价物。 ISO 32000-1 中的 NeedAppearancestrue 向 PDF 查看器指示 PDF 文件中的外观流丢失或不是最新的,因此应重新生成通过 PDF 查看器。另一方面,ISO 32000-2 要求所有注释(表单字段小部件是注释)具有最新的外观流。因此,NeedAppearances 用例不再出现在 PDF-2 中。
    【解决方案2】:

    我正在处理同样的问题。仅当我单击字段时才会显示文本。

    var document = PdfReader.Open("pristupy.pdf", PdfDocumentOpenMode.Modify);
    document.AcroForm.Fields[0].Value = new PdfString(user.LastName + " " + user.FirstName);
    document.AcroForm.Fields[1].Value = new PdfString(unit.Name);
    document.AcroForm.Fields[2].Value = new PdfString(system.Name);
    document.AcroForm.Fields[3].Value = new PdfString(accessApplication.AppliedDate.ToShortDateString());
    document.AcroForm.Fields[4].Value = new PdfString(roleAddString);
    document.AcroForm.Fields[5].Value = new PdfString(roleRemoveString);
    
    if (document.AcroForm.Elements.ContainsKey("/NeedAppearances"))
        document.AcroForm.Elements["/NeedAppearances"] = new PdfBoolean(true);
    else
        document.AcroForm.Elements.Add("/NeedAppearances", new PdfBoolean(true));
    document.Save("pdf.pdf");
    

    现在它可以正常工作了! (使用 PdfSHARP)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-24
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多