Hindi font is not getting displayed properly in TCPDF - php

Can anyone help me to lead the Hindi font properly using the TCPDF library? I have successfully installed the font as .php and .z files have been generated but when I am running the code it's not displaying the text. Please check the screenshot for ref.
I tried everything by following TCPDF guidelines but nothing is working. I tried mangal and freesans families as well but those are translating the text in the wrong way.
Print Input: नमस्ते आप कैसे
Output :
If anyone have any clue or solution then please answer to this issue.

You can try setting the header 'Content-Type', 'application/pdf' before outputting your pdf, like this:
$this->response->setHeader('Content-Type', 'application/pdf');
$pdf->Output('file.pdf', 'I');
Not sure if it works with Hindi characters, but it does with spanish accented characters and letters not included in the english alphabet

Related

Unable to save file with Thai characters filename

I'm currently trying to save a pdf file using mPDF library. My problem is when I try to output file using English filename, the filename is displayed correctly, but if the filename contains any Thai characters it became weird.
My mPDF outputs code.
$save_file = $s_code.'_'.$classroom.'.pdf';
$mpdf->Output('../../../upload/'.$save_file,'F');
With English filename it displayed correctly.
t10024_201.pdf
With Thai characters it doesn't.
เธ—เธช10024_201.pdf
I can't figure out what causes the problem.
The filename is restricted to the character set supported by the device (in this case, the server where mpdf is generating your pdfs), and doesn't actually reflect a problem with mpdf itself. [If you can add/write Thai characters within the pdf, just the filename doesn't reflect Thai characters].
You may need to configure the Content-Disposition headers for the webserver's response with PDF file. As an example, see this blog post that describes how a ColdFusion application developer dealt with saving files with French characters.
Thank you so much, Anson W Han.
It's about character encoding. I finally found a solution. I simply convert the filename to Thai edcoding using "iconv" and it displays correctly.
The code:
$mpdf->Output('../../../upload/'.iconv("UTF-8", "TIS-620",$save_file),'F');

How can I display Arabic text in fpdf?

I am using fpdf in php for developing pdf. I have to include some static Arabic or Farsi text to this pdf. I had used
$farsi_txt = iconv('UTF-8', 'ISO-8859-5', html_entity_decode('حضور محترم'));
$pdf->Write(5,$farsi_txt);
But the output was Blank.
When I had displayed it directly
$pdf->Write(5,'فغانستان کابل');
then the out put was like ٕغانستان کابل
When I had created a window to insert the arabic text to database then the output was حضور محترم
Is there any way to display this text as Arabic or Farsi in fpdf?
Found the answer for my question. I had replaced FPDF with TCPDF. TCPDF provides special fonts for Arabic and Farsi languages. I had got the correct output using TCPDF. I simply done this by switching font and $tpdf->setRTL(false); this sets the right to left alignment if arabic words.
TCPDF Download link
take a look here. This page specifically talks about adding new Fonts and encodings, which I believe is the issue as the PDF is missing the Arabic font and is unable to find a replacement for characters.

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

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:
Add fonts to pdf files (checked and files has font)
Create fields in pdf files with default font (Arial)
Change encoding in script (function fillForm) to ISO-8859-2
Change data values encoding (iconv or mb_convert_encoding)
Change functions encoding and data value encoding to ISO-8859-2
Flatten pdf after filling the form
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?
you need to run pdftk with need_appearances as an argument.
kudos to the guys from this issue on github.
I had similar issue.
Solved it with utf8_decode function. eg utf8_decode('Łukasz')
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.
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

html_entity_decode in FPDF

I Have the some problem als this post from 2 year ago on this website. I tried everything, but nothing help.
Does anybody over here a working solutions for this problem?
html_entity_decode in FPDF(using tFPDF extention)
I am using tFPDF to generate a PDF. The php file is UTF-8 encoded. I want © for example, to be output in the pdf as the copyright symbol.
I have tried iconv, html_entity_decode, htmlspecialchars_decode. When I take the string I am trying to decode and hard-code it in to a different file and decode it, it works as expected. So for some reason it is not being output in the PDF. I have tried output buffering. I am using DejaVuSansCondensed.ttf (true type fonts).
Link to tFPDF: http://fpdf.org/en/script/script92.php
I am out of ideas. I tried double decoding, I checked everywhere to make sure it was not being encoded anywhere else.
Help!

An error occurred while displaying Korean in PHP

Hi all I need your help for my problem.
I try to display text (Korean) from a .txt file but the output is different.
I have a .txt file contains Korean characters like this
냐는 한국을 사랑
but when i try :
$str= file_get_contents($path."result.txt");
echo $str;
on the browser the result came out like this : �먮뒗 �쒓뎅�� �щ옉
but It's OK when i just echo "냐는 한국을 사랑"
IS there something wrong ?
Thank for your help
Either use header("Content-Type: text/html; charset=UTF-8") in your php file or a meta tag in your html <meta charset='utf-8'>. And make sure the font you are using supports unicode characters you need.
Apparently the character encoding of the file is different from the character encoding of the HTML document that your code is generating.
You could dynamically convert the text data in PHP, or you could just use a suitable conversion program to convert the text file. You could just open the text file in a text editor and use Save As to save it as UTF-8 encoded (without BOM), assuming that your PHP is generating a UTF-8 encoded document.
I struggled a while fixing this problem until I discovered this which works perfectly for me:
echo call_user_func_array('mb_convert_encoding', array("행동 방식",'HTML-ENTITIES','UTF-8'));

Categories