0

I am trying to fill a pdf template with Chinese and Japanese Language. TCPDF is the library used and for filling data to pdf used forge_fdf. Following is the code used

passthru("pdftk $abs_pdf_path fill_form $fdf_fn output $certFileName owner_pw foopass allow DegradedPrinting flatten");

$abs_pdf_path is path of my template file. $fdf_fn is a temporary file holding data as follows which is used to fill the template

%FDF-1.2
%����
1 0 obj
<<
/FDF << /Fields [ << /T (input_name) /V (Chinese : 这是一个测试文本) /ClrF 2 /ClrFf 1 >>
<< /T (input_date) /V (2021-08-12 00:00:00) /ClrF 2 /ClrFf 1 >>
<< /T (certificate_number) /V (IMP21JKX5L8K) /ClrF 2 /ClrFf 1 >>
<< /T (certid) /V (IMP21JKX5L8K) /ClrF 2 /ClrFf 1 >>
<< /T (timestamp) /V (2021-08-18 12:14:49) /ClrF 2 /ClrFf 1 >>
]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF

$certFileName is the pdf file that need to output the result.

But when the pdf is generated the Unicode characters are printing like this "Chinese : 这是一个测试文本"

How to resolve this ?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • Please: do links to external images. You should include the image directly in the question. I'm not opening random links anyway. Note: often the reason is "font". Unicode is "just" linking a number to a name. How to display things are left to font. – Giacomo Catenazzi Aug 18 '21 at 13:03
  • @GiacomoCatenazzi . I have included the text in the image directly in question now. Font used in the pdf are Unicode supporting , the same is working when trying to generate a pdf , it is only failing while writing/filling to a given template which is done using passthru. – Anuja Nair Aug 18 '21 at 13:10
  • 1
    At first glance it looks like some data that is UTF-8 encoded is interpreted as some other encoding. Check if `pdftk` has some switch to specify the input encoding. – Joachim Sauer Aug 18 '21 at 13:13
  • A [mojibake](https://en.wikipedia.org/wiki/Mojibake) case: `mb_convert_encoding( "Chinese : 这是一个测试文本", "Windows-1252", "UTF-8")` returns `'Chinese : 这是一个测试文本'`. Read [Support utf-8 AND flatten](https://github.com/mikehaertl/php-pdftk/issues/27) as well. – JosefZ Aug 18 '21 at 14:01

0 Answers0