Missing characters in filled pdf using PDFTk with encoding UTF-8

£可爱£侵袭症+ 提交于 2019-12-08 02:45:21

问题


I'm trying to fill pdf documents using PDFTk. Script working fine, it fills inputs in form but I don't get special characters [polish charset: UTF-8 or ISO-8859-2].

Script: https://github.com/mikehaertl/php-pdftk

The weird thing is that generated pdf actually has polish characters when I click on field.

Before click:

After click on field:


Default encoding is set to UTF-8. The problem is that PDFTk can't use chars outside the standard ASCII with FDF form fill. It doesn't allow multi-byte characters.

What I did:

  1. Add fonts to pdf files (checked and files has font)
  2. Create fields in pdf files with default font (Arial)
  3. Change encoding in script (function fillForm) to ISO-8859-2
  4. Change data values encoding (iconv or mb_convert_encoding)
  5. Change functions encoding and data value encoding to ISO-8859-2
  6. Flatten pdf after filling the form
  7. Read all topics about this problem in stackoverflow, google

UPDATE (25.03.2016): Findout that pdf documents works fine on some computers. Some people have polish characters and other don't. All of us have right fonts (with polish charset). I used default Arial or Times New Roman. Fonts are also embed in that file.

Any ideas?


回答1:


you need to run pdftk with need_appearances as an argument.

kudos to the guys from this issue on github.




回答2:


I had similar issue. Solved it with utf8_decode function. eg utf8_decode('Łukasz')




回答3:


I could not find how to change font, so my solution - use itext, https://itextpdf.com/en/resources/examples/itext-5/filling-out-forms

wrote for my project https://github.com/dddeeemmmooonnn/pdf_form_filler



来源:https://stackoverflow.com/questions/36196850/missing-characters-in-filled-pdf-using-pdftk-with-encoding-utf-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!