5

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:

enter image description here

After click on field:

enter image description here


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?

Michał Lipa
  • 968
  • 2
  • 12
  • 22
  • i have this same issue with even with Times New Roman fonts. But its because of LibreOffice PDF export, – Andrewboy Feb 04 '20 at 00:52
  • Its seems its not because of missing font characters.My issue begin right after exporting PDF from LibreOffice Writer – Andrewboy Feb 04 '20 at 18:44

4 Answers4

8

you need to run pdftk with need_appearances as an argument.

kudos to the guys from this issue on github.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
0

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

breq
  • 24,412
  • 26
  • 65
  • 106
0

The best results (without flatten) I got when I was creating FDF file with UTF-8 values encoded into UTF-18BE

chr(0xfe) . chr(0xff) . str_replace(array('\\', '(', ')'), array('\\\\', '\(', '\)'), mb_convert_encoding($string, 'UTF-16BE'));

Your library works quite well but ie. when I open the PDF generated with it directly in Safari on MACOS it does not show polish chars until I click the field. When I open it with Adobe Reader - it works fine.

-2

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

Dmitry Turov
  • 29
  • 1
  • 2
  • 1
    Please show the portion in your project where you used itext to solve similar problem. – Nabil Farhan Mar 20 '19 at 05:37
  • @Nabil Farhan I didn't understand the question exactly. I need to fill out the form in Cyrillic in laravel project. pdftk did not display cyrillic until you click to field, font problem – Dmitry Turov Mar 22 '19 at 00:39