mikehaertl/php-pdftk

Wrong diacritic characters filled

jadamec opened this issue · 5 comments

Hi there, why my diacritic characters are wrongly filled into fields, please? From the +ľščťžýáíé I got this in Google Chrome (also when trying to print via Adobe Acrobat Reader):
Snímka obrazovky 2022-06-16 125756

When filling directly from Adobe Acrobat Reader, these characters work correctly...

$pdf = new Pdf('/Šablóna 014.pdf', [
  'locale' => 'en_US.utf8',
  'procEnv' => [
    'LANG' => 'en_US.utf-8',
  ],
]);

$pdf->fillForm([
    'name' => '+ľščťžýáíé'
  ])
  ->needAppearances()
  ->send('Šablóna 014 vyplnené.pdf');

This is very likely rather a problem with wrong fonts embedded in the PDF. We can't fix this. You have to edit the PDF and use a font for that form field that includes those characters.

It has a basic Helvetica font (supports all characters). As I said, when filling directly from Adobe Acrobat Reader.. everything is good.

Acrobat Reader can do all kind of things when you fill a form. I think it can even modify the PDF form to use a different font if a character you entered is not supported. pdftk can't do this.

What happens in the background with php-pdftkis that it creates a XML file in XFDF format. This file then contains your form data. pdftk is then used to combine your PDF with the data from XML. That's all we do and if this doesn't work something must be wrong with your PDF.

Also check out this comment where someone says, that the default font Helvetica will not support all characters: #4 (comment)

From my own projects I know that everything works fine if the PDF is created with the right font embedded. I just can't provide any help on this as I always got the PDFs from someone else and never had these problems.

Thank you for your time! Changing font from Helvetica to Myriad Pro (and closing the field styles) fixed this problem.