代码之家  ›  专栏  ›  技术社区  ›  Juan Antonio

pdftk-使用FDF自动填充PDF表单

  •  0
  • Juan Antonio  · 技术社区  · 7 年前

    首先,感谢您抽出时间阅读我的问题。

    我有一个PDF文件,其中有一个部分,当你填充它时,它会填充PDF的其他部分。

    基本上,您输入姓氏,它会填充PDF中需要姓氏的部分。

    我需要用一个PHP脚本来填充姓氏,该脚本从HTML表单中获取姓氏。我需要启用自动填充功能。

    姓氏的field\u name为:

    FieldType: Text
    FieldName: MCSA-5875[0].Page1[0].driverPersonal[0].nameLast[0]
    FieldNameAlt: Enter the driver's last name.
    FieldFlags: 0
    FieldJustification: Left
    

    我为填写表格而创建的FDF文件是:

    %FDF-1.2
    %,,oe"
    1 0 obj
    <<
    /FDF << /Fields [<</T(MCSA-5875[0].Page1[0].driverPersonal[0].nameLast[0])/V(Smith)>>"] >> >>
    endobj
    trailer
    <</Root 1 0 R>>
    %%EOF;
    

    其中,“Smith”是一个姓氏示例。

    当我运行以下命令(填写PDF表单)时:

    pdftk form.pdf fill_form output.fdf output output.pdf
    

    我得到以下错误:

    Unhandled Java Exception in create_output():
    java.lang.ClassCastException: pdftk.com.lowagie.text.pdf.PdfLiteral cannot be cast to pdftk.com.lowagie.text.pdf.PdfDictionary
       at 0x0059a84e (Unknown Source)
       at 0x0059ad42 (Unknown Source)
       at 0x005e9bd4 (Unknown Source)
       at 0x005ba4a4 (Unknown Source)
       at 0x005b2044 (Unknown Source)
       at 0x0059231e (Unknown Source)
       at 0x004721bd (Unknown Source)
       at 0x00472562 (Unknown Source)
       at 0x00472045 (Unknown Source)
       at 0x004df3e2 (Unknown Source)
       at 0x004df38a (Unknown Source)
       at 0x00471e74 (Unknown Source)
    

    你能帮我找到这个问题的解决办法吗?

    提前感谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Juan Antonio    7 年前

    好吧,我做到了!我刚刚使用了以下开源解决方案: https://github.com/Tadelsucht/BulkPDF

    我们使用HTML表单和PHP后端按需填写csv模板。

    然后,我们使用PHP通过命令行调用应用程序