在 PHP 中使用 utf-8 字符将 FDF / XFDF 表单展平为 PDF

发布于 2024-09-28 08:53:34 字数 611 浏览 0 评论 0原文

我的场景:

  • 带有表单字段的 PDF 模板: template.pdf
  • 包含要填写的数据的 XFDF 文件: fieldData.xfdf

现在我需要将这些文件组合起来并保存到文件中。压扁了。 pdftk 在 php 中轻松完成这项工作:

exec("pdftk template.pdf fill_form fieldData.xfdf output flatFile.pdf flatten");

不幸的是,这不适用于完整的 utf-8 支持。 例如:西里尔字母和希腊字母被打乱。我使用 Arial 来实现此目的,并使用 unicode 字符集。

  • 我怎样才能扁平化我的 unicode 文件?
  • 有没有其他提供 unicode 支持的 pdf 工具?
  • pdftk 有我缺少的 unicode 开关吗?

编辑 1:由于这个问题已经超过 9 个月没有得到解决,我决定开始悬赏它。如果有选项可以赞助 pdftk 中的功能或错误修复,我很乐意捐赠。

编辑2:我不再从事这个项目了,所以我无法验证新的答案。如果有人有类似的问题,我很高兴他们能以我的方式做出回应。

My scenario:

  • A PDF template with formfields: template.pdf
  • An XFDF file that contains the data to be filled in: fieldData.xfdf

Now I need to have these to files combined & flattened.
pdftk does the job easily within php:

exec("pdftk template.pdf fill_form fieldData.xfdf output flatFile.pdf flatten");

Unfortunately this does not work with full utf-8 support.
For example: Cyrillic and greek letters get scrambled. I used Arial for this, with an unicode character set.

  • How can I accomplish to flatten my unicode files?
  • Is there any other pdf tool that offers unicode support?
  • Does pdftk have an unicode switch that I am missing?

EDIT 1: As this question has not been solved for more then 9 month, I decided to start a bounty for it. In case there are options to sponsor a feature or a bugfix in pdftk, I'd be glad to donate.

EDIT 2: I am not working on this project anymore, so I cannot verify new answers. If anyone has a similar problem, I am glad if they can respond in my favour.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

得不到的就毁灭 2024-10-05 08:53:34

我发现通过使用 Jon 的模板,但使用 DomDocument,数字编码已为我处理并且运行良好。我的轻微变化如下:

$xml = new DOMDocument( '1.0', 'UTF-8' );

$rootNode = $xml->createElement( 'xfdf' );
$rootNode->setAttribute( 'xmlns', 'http://ns.adobe.com/xfdf/' );
$rootNode->setAttribute( 'xml:space', 'preserve' );
$xml->appendChild( $rootNode );

$fieldsNode = $xml->createElement( 'fields' );
$rootNode->appendChild( $fieldsNode );

foreach ( $fields as $field => $value )
{
    $fieldNode = $xml->createElement( 'field' );
    $fieldNode->setAttribute( 'name', $field );
    $fieldsNode->appendChild( $fieldNode );

    $valueNode = $xml->createElement( 'value' );
    $valueNode->appendChild( $xml->createTextNode( $value ) );
    $fieldNode->appendChild( $valueNode );
}

$xml->save( $file );

I found by using Jon's template but using the DomDocument the numeric encoding was handled for me and worked well. My slight variation is below:

$xml = new DOMDocument( '1.0', 'UTF-8' );

$rootNode = $xml->createElement( 'xfdf' );
$rootNode->setAttribute( 'xmlns', 'http://ns.adobe.com/xfdf/' );
$rootNode->setAttribute( 'xml:space', 'preserve' );
$xml->appendChild( $rootNode );

$fieldsNode = $xml->createElement( 'fields' );
$rootNode->appendChild( $fieldsNode );

foreach ( $fields as $field => $value )
{
    $fieldNode = $xml->createElement( 'field' );
    $fieldNode->setAttribute( 'name', $field );
    $fieldsNode->appendChild( $fieldNode );

    $valueNode = $xml->createElement( 'value' );
    $valueNode->appendChild( $xml->createTextNode( $value ) );
    $fieldNode->appendChild( $valueNode );
}

$xml->save( $file );
百思不得你姐 2024-10-05 08:53:34

您可以尝试 http://www.adobe.com/products/livecycle/designer 的试用版/ 并查看它生成的 PDF 文件。

您可以尝试的另一个商业软件是http://www.appligent.com/fdfmerge。请参阅 http://146.145.110.1/docs/userguide/FDFMergeUserGuide.pdf 中的第 16 页了解它如何使用 UTF-8 处理 xFDF。

我还查看了 FDF 规范 http://partners。 adobe.com/public/developer/en/xml/xfdf_2.0.pdf
第 12 页上指出:

Although XFDF is encoded in UTF-8, double byte characters are encoded as character references when 
exported from Acrobat. 
For example, the Japanese double byte characters ,  , and  are exported to XFDF using 
three character references. Here is an example of double byte characters in a form field: 
  ...
<fields>  
  <field name="Text1"> 
     <value>Here are 3 UTF-8 double byte  
        characters: あいう
</value>  
  </field>  
</fields> ... 

我浏览了 pdftk-1.44-dist/java/com/lowagie/text/pdf/XfdfReader.java。它似乎对输入没有做任何特别的事情。

当您将奇怪的字符编码为 xFDF 输入中的字符引用时,也许 pdftk 会执行您想要的操作。

You could try the trial version of http://www.adobe.com/products/livecycle/designer/ and see what PDF files it generates.

Another commercial software you could try is http://www.appligent.com/fdfmerge. See page 16 in http://146.145.110.1/docs/userguide/FDFMergeUserGuide.pdf for how it handles xFDF with UTF-8.

I also had a look at the FDF specification http://partners.adobe.com/public/developer/en/xml/xfdf_2.0.pdf
On page 12 it states:

Although XFDF is encoded in UTF-8, double byte characters are encoded as character references when 
exported from Acrobat. 
For example, the Japanese double byte characters ,  , and  are exported to XFDF using 
three character references. Here is an example of double byte characters in a form field: 
  ...
<fields>  
  <field name="Text1"> 
     <value>Here are 3 UTF-8 double byte  
        characters: あいう
</value>  
  </field>  
</fields> ... 

I looked through pdftk-1.44-dist/java/com/lowagie/text/pdf/XfdfReader.java. It doesn't seem to do anything special with the input.

Maybe pdftk will do what you want, when you encode the weird characters as character references in your xFDF input.

明月夜 2024-10-05 08:53:34

在 Win7 机器上使用 pdftk 1.44 我遇到了与 xfdf 文件相同的问题,而 fdf 工作正常。我制作了一个没有任何特殊字符(仅 ANSI)的 xfdf 文件,但 pdftk 再次崩溃。我给开发商发邮件了。不幸的是直到现在还没有答案。

Using the pdftk 1.44 on a Win7 machine I encounter the same problems with xfdf-files whereas fdf works fine. I made a xfdf-file without any special characters (only ANSI) but pdftk crashed again. I mailed the developper. Unfortunately no answer until now.

缱绻入梦 2024-10-05 08:53:34

不幸的是,UTF-8 字符编码不适用于源 .xfdf 文件中非 ASCII 字符的十进制或十六进制引用。 PDFTK v.1.44。

Unfortunately, UTF-8 character encoding does not work neither with decimal nor hexadecimal references of non-ASCII characters in source .xfdf file. PDFTK v. 1.44.

浅唱々樱花落 2024-10-05 08:53:34

我在这方面取得了一些进展。从 http://koivi.com/fill-pdf-form-fields/,我修改了值编码以输出 ASCII 范围之外的任何字符的数字代码。

现在使用pitulski的特殊字符串:

Poznań Śródmieście Ćwiartka Ósma 输出 Pozna ródmiecie wiartka Ósma 并叠加一些盒子形状

ęóąśłżźćńĘÓĄŚŁŻŹĆŃ 输出 óÓ > 有更多的盒子形状。我认为盒子形状可能是我的服务器无法识别的字符。

我尝试使用一些法语字符:ùûüÿ€'“”»àâæçéèêëïôœÙÛÜŸÀÂÆÇÉÈÊËÏÎÔ,它们都显示正常,但其中一些是重叠的。

--编辑-- 我只是尝试将这些手动输入到表单中,并得到相同的结果减去框形状(使用 Evince)。然后我尝试使用不同的表单(由其他人创建) - 输入ęóąśłżźćńĘÓĄŚŁŻŹĆŃ后,显示ółÓŁ。看起来这取决于文档的嵌入字体中包含哪些字符。

/*
KOIVI HTML Form to FDF Parser for PHP (C) 2004 Justin Koivisto
Version 1.2.?
Last Modified: 2013/01/17 - Jon Hulka(jon dot hulka at gmail dot com)
  - changed character encoding, all non-ascii characters get encoded as numeric character references

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2.1 of the License, or (at
    your option) any later version.

    This library is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this library; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

    Full license agreement notice can be found in the LICENSE file contained
    within this distribution package.

    Justin Koivisto
    justin dot koivisto at gmail dot com
    http://koivi.com
*/

/**
 * createXFDF
 * 
 * Tales values passed via associative array and generates XFDF file format
 * with that data for the pdf address sullpiled.
 * 
 * @param string $file The pdf file - url or file path accepted
 * @param array $info data to use in key/value pairs no more than 2 dimensions
 * @param string $enc default UTF-8, match server output: default_charset in php.ini
 * @return string The XFDF data for acrobat reader to use in the pdf form file
 */
function createXFDF($file,$info,$enc='UTF-8'){
    $data=
'<?xml version="1.0" encoding="'.$enc.'"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
    <fields>';
    foreach($info as $field => $val){
        $data.='
        <field name="'.$field.'">';
        if(is_array($val)){
            foreach($val as $opt)
//2013.01.17 - Jon Hulka - all non-ascii characters get character references
            $data.='
            <value>'.mb_encode_numericentity(htmlspecialchars($opt),array(0x0080, 0xffff, 0, 0xffff), 'UTF-8').'</value>';
//                $data.='<value>'.htmlentities($opt,ENT_COMPAT,$enc).'</value>'."\n";
        }else{
            $data.='
            <value>'.mb_encode_numericentity(htmlspecialchars($val),array(0x0080, 0xffff, 0, 0xffff), 'UTF-8').'</value>';
//            $data.='<value>'.htmlentities($val,ENT_COMPAT,$enc).'</value>'."\n";
        }
        $data.='
        </field>';
    }
    $data.='
    </fields>
    <ids original="'.md5($file).'" modified="'.time().'" />
    <f href="'.$file.'" />
</xfdf>';
    return $data;
}

I made some progress on this. Starting with code from http://koivi.com/fill-pdf-form-fields/, I modified the value encoding to output numeric codes for any characters outside the ascii range.

Now with pitulski's special strings:

Poznań Śródmieście Ćwiartka Ósma outputs Pozna ródmiecie wiartka Ósma with some box shapes superimposed

ęóąśłżźćńĘÓĄŚŁŻŹĆŃ outputs óÓ with more box shapes. I think it may be that the box shapes are characters my server doesn't recognize.

I tried it with some French characters: ùûüÿ€’“”«»àâæçéèêëïôœÙÛÜŸÀÂÆÇÉÈÊËÏÎÔ and they all came out OK, but some of them were overlapping.

--edit-- I just tried entering these manually into the form and got the same result minus the box shapes (using Evince). I then tried with a different form (created by someone else) - after entering ęóąśłżźćńĘÓĄŚŁŻŹĆŃ, ółÓŁ was displayed. It looks like it depends which characters are included in the document's embedded fonts.

/*
KOIVI HTML Form to FDF Parser for PHP (C) 2004 Justin Koivisto
Version 1.2.?
Last Modified: 2013/01/17 - Jon Hulka(jon dot hulka at gmail dot com)
  - changed character encoding, all non-ascii characters get encoded as numeric character references

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2.1 of the License, or (at
    your option) any later version.

    This library is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this library; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

    Full license agreement notice can be found in the LICENSE file contained
    within this distribution package.

    Justin Koivisto
    justin dot koivisto at gmail dot com
    http://koivi.com
*/

/**
 * createXFDF
 * 
 * Tales values passed via associative array and generates XFDF file format
 * with that data for the pdf address sullpiled.
 * 
 * @param string $file The pdf file - url or file path accepted
 * @param array $info data to use in key/value pairs no more than 2 dimensions
 * @param string $enc default UTF-8, match server output: default_charset in php.ini
 * @return string The XFDF data for acrobat reader to use in the pdf form file
 */
function createXFDF($file,$info,$enc='UTF-8'){
    $data=
'<?xml version="1.0" encoding="'.$enc.'"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
    <fields>';
    foreach($info as $field => $val){
        $data.='
        <field name="'.$field.'">';
        if(is_array($val)){
            foreach($val as $opt)
//2013.01.17 - Jon Hulka - all non-ascii characters get character references
            $data.='
            <value>'.mb_encode_numericentity(htmlspecialchars($opt),array(0x0080, 0xffff, 0, 0xffff), 'UTF-8').'</value>';
//                $data.='<value>'.htmlentities($opt,ENT_COMPAT,$enc).'</value>'."\n";
        }else{
            $data.='
            <value>'.mb_encode_numericentity(htmlspecialchars($val),array(0x0080, 0xffff, 0, 0xffff), 'UTF-8').'</value>';
//            $data.='<value>'.htmlentities($val,ENT_COMPAT,$enc).'</value>'."\n";
        }
        $data.='
        </field>';
    }
    $data.='
    </fields>
    <ids original="'.md5($file).'" modified="'.time().'" />
    <f href="'.$file.'" />
</xfdf>';
    return $data;
}
-黛色若梦 2024-10-05 08:53:34

虽然 pdftk 似乎不支持 FDF 文件中的 UTF-8,但我发现在

iconv -f utf-8 -t ISO_8859-1

将该 FDF 文件转换为 ISO-Latin-1 的管道中,那么至少 Latin-1 代码页中的那些字符仍然会存在得到适当的代表。

While pdftk doesn't appear to support UTF-8 in the FDF file, I found that with

iconv -f utf-8 -t ISO_8859-1

in the pipeline converting that FDF file to ISO-Latin-1, then at least those characters that are in the Latin-1 code page will still be represented properly.

半城柳色半声笛 2024-10-05 08:53:34

这个问题我也找了好久了,终于找到解决办法了!

那么,让我们开始吧。

  1. 下载并安装最新版本的pdftk
# PDFTK
RUN apk add openjdk8 \
    && cd /tmp \
    && wget https://gitlab.com/pdftk-java/pdftk/-/jobs/1507074845/artifacts/raw/build/libs/pdftk-all.jar \
    && mv pdftk-all.jar pdftk.jar \
    && echo '#!/usr/bin/env bash' > pdftk \
    && echo 'java -jar "$0.jar" "$@"' >> pdftk \
    && chmod 775 pdftk* \
    && mv pdftk* /usr/local/bin \
    && pdftk -version
  1. 在Adobe Acrobat Reader中打开您的PDF表单并查看字段选项,您需要检测字体,例如Helvetica,下载此字体。
  2. 使用 flatten 选项填写表单
/usr/local/bin/pdftk A=form.pdf fill_form xfdf.xml output out.pdf drop_xfa need_appearances flatten replacement_font /path/to/font/HelveticaRegular.ttf

xfdf.xml 示例:

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
    <fields>
        <field name="Check Box 136">
            <value>Your value | Значение (Cyrillic)</value>
        </field>
    </fields>
</xfdf>

享受 :)

I have been solving this issue for a long time, and finally I have found the solution!

so, let's start.

  1. download and install the latest version of pdftk
# PDFTK
RUN apk add openjdk8 \
    && cd /tmp \
    && wget https://gitlab.com/pdftk-java/pdftk/-/jobs/1507074845/artifacts/raw/build/libs/pdftk-all.jar \
    && mv pdftk-all.jar pdftk.jar \
    && echo '#!/usr/bin/env bash' > pdftk \
    && echo 'java -jar "$0.jar" "$@"' >> pdftk \
    && chmod 775 pdftk* \
    && mv pdftk* /usr/local/bin \
    && pdftk -version
  1. Open your PDF Form in Adobe Acrobat Reader and look at field options, you need to detect the font, for example Helvetica, download this font.
  2. Fill the form with flatten option
/usr/local/bin/pdftk A=form.pdf fill_form xfdf.xml output out.pdf drop_xfa need_appearances flatten replacement_font /path/to/font/HelveticaRegular.ttf

xfdf.xml example:

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
    <fields>
        <field name="Check Box 136">
            <value>Your value | Значение (Cyrillic)</value>
        </field>
    </fields>
</xfdf>

Enjoy :)

罪#恶を代价 2024-10-05 08:53:34

PDFTK 的版本是什么?
我对波兰字符(utf-8)尝试了同样的操作。

对我不起作用。

pdftk.exe、libiconv2.dll 来自: http://www.pdflabs.com/docs/install -pdftk/

Windows 7,cmd,file.pdf + file.fdf -> new.pdf

pdftk file.pdf fill_form file.xfdf output new.pdf flatten

Unhandled Java Exception:
java.lang.NoClassDefFoundError: gnu.gcj.convert.Input_UTF8 not found in [file:.\, core:/]
   at 0x005a3abe (Unknown Source)
   at 0x005a3fb2 (Unknown Source)
   at 0x006119f4 (Unknown Source)
   at 0x00649ee4 (Unknown Source)
   at 0x005b4c44 (Unknown Source)
   at 0x005470a9 (Unknown Source)
   at 0x00549c52 (Unknown Source)
   at 0x0059d348 (Unknown Source)
   at 0x007323c9 (Unknown Source)
   at 0x0054715a (Unknown Source)
   at 0x00562349 (Unknown Source)

但是,对于具有相同内容的 FDF 文件,它可以正常工作。
但是new.PDF中的字符很糟糕。

pdftk file.pdf fill_form file.fdf 输出 new.pdf 压平

---FDF---

%FDF-1.2
%âãÏÓ
1 0 obj<</FDF<</F(file.pdf)
/Fields[
<</T(Miejsce)/V(666 Poznań Śródmieście Ćwiartka Ósma)>>
<</T(Nr)/V(ęóąśłżźćńĘÓĄŚŁŻŹĆŃ)>>
]>>>>
endobj
trailer
<</Root 1 0 R>>
%%EOF

---XFDF---

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<f href="file.pdf"/>
<fields>
<field name="Miejsce">
<value>666 Poznań Śródmieście Ćwiartka Ósma</value>
</field>
<field name="Nr">
<value>ęóąśłżźćńĘÓĄŚŁŻŹĆŃ</value>
</field>
</fields>
</xfdf>

---PDF---

Miejsce: 666 PoznaÅ— ÅıródmieÅłcie ăwiartka Ãfisma
Nr: ÄŽÃ³Ä–ÅłÅ‡Å¼ÅºÄ⁄Å—ÄŸÃfiÄ—ÅıņŻŹăÅ

What PDFTK's version?
I tried the same thing with Polish characters (utf-8).

Does not work for me.

pdftk.exe, libiconv2.dll from: http://www.pdflabs.com/docs/install-pdftk/

Windows 7, cmd, file.pdf + file.fdf -> new.pdf

pdftk file.pdf fill_form file.xfdf output new.pdf flatten

Unhandled Java Exception:
java.lang.NoClassDefFoundError: gnu.gcj.convert.Input_UTF8 not found in [file:.\, core:/]
   at 0x005a3abe (Unknown Source)
   at 0x005a3fb2 (Unknown Source)
   at 0x006119f4 (Unknown Source)
   at 0x00649ee4 (Unknown Source)
   at 0x005b4c44 (Unknown Source)
   at 0x005470a9 (Unknown Source)
   at 0x00549c52 (Unknown Source)
   at 0x0059d348 (Unknown Source)
   at 0x007323c9 (Unknown Source)
   at 0x0054715a (Unknown Source)
   at 0x00562349 (Unknown Source)

But, with FDF file, with the same content, it worked properly.
But the characters in new.PDF are bad.

pdftk file.pdf fill_form file.fdf output new.pdf flatten

---FDF---

%FDF-1.2
%âãÏÓ
1 0 obj<</FDF<</F(file.pdf)
/Fields[
<</T(Miejsce)/V(666 Poznań Śródmieście Ćwiartka Ósma)>>
<</T(Nr)/V(ęóąśłżźćńĘÓĄŚŁŻŹĆŃ)>>
]>>>>
endobj
trailer
<</Root 1 0 R>>
%%EOF

---XFDF---

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<f href="file.pdf"/>
<fields>
<field name="Miejsce">
<value>666 Poznań Śródmieście Ćwiartka Ósma</value>
</field>
<field name="Nr">
<value>ęóąśłżźćńĘÓĄŚŁŻŹĆŃ</value>
</field>
</fields>
</xfdf>

---PDF---

Miejsce: 666 PoznaÅ— ÅıródmieÅłcie ăwiartka Ãfisma
Nr: ÄŽÃ³Ä–ÅłÅ‡Å¼ÅºÄ⁄Å—ÄŸÃfiÄ—ÅıņŻŹăÅ
丶视觉 2024-10-05 08:53:34

您可以通过使用 \ddd 给出八进制的 unicode 代码来引入 utf-8 字符

You can introduce utf-8 characters by giving their unicode code in octal with \ddd

╄→承喏 2024-10-05 08:53:34

为了解决这个问题,我编写了 PdfFormFillerUTF-8: http://sourceforge.net/projects/pdfformfiller2/

To solve this, I wrote PdfFormFillerUTF-8: http://sourceforge.net/projects/pdfformfiller2/

残龙傲雪 2024-10-05 08:53:34

的直接替代品

有一个 pdftk 工具Mcpdfhttps://github。 com/m-click/mcpdf

解决填写表单时的 unicode 问题。适用于我的 CP1250 角色(中欧)。

来自项目页面:

以下命令将 DATA.xfdf 中的表单数据填充到 FORM.pdf 中
并将结果写入 RESULT.pdf。它还将文档展平为
防止进一步编辑:

java -jar mcpdf.jar FORM.pdf fill_form - output - flatten < DATA.xfdf > RESULT.pdf

这与通常的 PDFtk 命令完全对应:

pdftk FORM.pdf fill_form - output - flatten < DATA.xfdf > RESULT.pdf

请注意,您需要安装 JRE。

There is a drop-in replacement for pdftk tool

Mcpdf: https://github.com/m-click/mcpdf

that solves unicode issues when filling forms. Works for me with CP1250 characters (Central Europe).

From project page:

the following command fills in form data from DATA.xfdf into FORM.pdf
and writes the result to RESULT.pdf. It also flattens the document to
prevent further editing:

java -jar mcpdf.jar FORM.pdf fill_form - output - flatten < DATA.xfdf > RESULT.pdf

This corresponds exactly to the usual PDFtk command:

pdftk FORM.pdf fill_form - output - flatten < DATA.xfdf > RESULT.pdf

Note that you need to have JRE installed.

人生百味 2024-10-05 08:53:34

我通过使用 utf-8 编码创建 xfdf 文件,设法使其与 pdftk 一起使用。

经过多次尝试,但使其按预期工作的是添加“need_appearances”,

这里是一个示例:

pdftk source.pdf fill_form data.xfdf output output.pdf need_appearances

I have managed to make it work with pdftk by creating a xfdf file with utf-8 encoding.

it took several tried but what make it work as exepcted was to add 'need_appearances'

here is an example:

pdftk source.pdf fill_form data.xfdf output output.pdf need_appearances
云裳 2024-10-05 08:53:34

pdftk 支持 UTF-16BE 编码。从 UTF-8 转换为 UTF-16BE 并不困难。

请参阅:使用 PDFTk 填充 PDF 时出现奇怪的字符

pdftk supports encoding in UTF-16BE. It's not that difficult to convert from UTF-8 to UTF-16BE.

See: Weird characters when filling PDF with PDFTk

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文