Myself trying to generate pdf files in Kannada font using fpdf and php as,
require_once('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddFont('Baraha','','baraha.php');
$pdf->AddPage();
$pdf->SetFont('Baraha','',35);
$pdf->Write(10,' cheluva kannaDa nADu');
$pdf->Output();
Tried using baraha.ttf, tunga.ttf, lohit.ttf etc but every font gives jumbled output. Below is the output for baraha.ttf font for the above line. How to output correctly in Kannada?
In Braraha font:
In Lohit Font:
Followed both this and this tutorials.
EDIT: The correct Kannada sentence is ಚೆಲುವ ಕನ್ನಡ ನಾಡು for cheluva kannaDa nADu. Also please suggest other fonts for correct Kannada sentences. FYI, the same jumbled words are appearing in the case of tcpdf php library and pdfmake.js javascript library as well. So can anyone please suggest a best library (either javascript or php) for pdf generation.
Related
I am trying to export to PDF using FPDF and TCPDF php library. I found that the emojis like 😁 😀 💃🏻 ❤️ 🥳 where not converted. Only ️️some rectangle box there in generated pdf. I also tried tfpdf.
$text = "There is my text 😁 , 😀 and emojis 💃🏻 ❤️ 🥳";
require('tfpdf/tfpdf.php');
$pdf = new tFPDF();
$pdf->AddPage();
//Add a Unicode font (uses UTF-8)
$pdf->AddFont('Segoe UI Symbol','','seguisym.ttf',true); // DejaVuSans.ttf
$pdf->SetFont('Segoe UI Symbol','',12);
$pdf->Write(8,$text);
$pdf->Output();
I also tried different font. But didn't work for me. Can any one help me in this regard?
Sadly fPDF, TCPDF nor tFPDF can't print those characters. Issue is, these characters are not part of BMP, they are expressed with surrogate pairs, meaning they behave like multiple characters in UTF-16 (because of that one emoticon is printed as 2 rectangle boxes, not one) and also they have codepoint above 65535. However all mentioned PDF libraries relies on codepoint index being <= 65535 as well as TFontFile class reading TTF files.
You would also need to add TTF file having complete set of Unicode charset, or at least emoticons. Most fonts does not have it. This brings another issue for PDF library, which would probably need to have support for fallback font, which will be used when codepoint is not found in main font (for example you want to print text in Gotham, but since that does not include emoji, use other font for them). Btw for example emoji font "Noto Color Emoji" has 23 MB TTF file. So it gets big easily.
Anyway, all of the above can be added to PDF libraries, but it will require some effort. I am planning to do it for my needs as well sometimes. I think it will take roughly 1 man day.
Alternativelly, you might try something more robust like mPDF, but that library is huge, slow and require complete rewrite of your fPDF code. Also can't guarantee it can print emojis as well.
I want to write a hindi text in my pdf.
At first, I downloaded the ttf font file from google fonts
After that I included the ttf file inside font < unifont
After that, I added the fonts into my code:
<?php
require('tfpdf.php');
$pdf = new tFPDF();
$pdf->AddPage();
$pdf->AddFont('NotoSerifDevanagari-Regular','','NotoSerifDevanagari-Regular.ttf',true);
$pdf->SetFont('NotoSerifDevanagari-Regular','',10);
$pdf->Cell(40,10,'पूसीरे के रेसुब ने नाबालिगों समेत 12 लोगों को बचाया');
$pdf->Output();
?>
The resultant text in the pdf shows like this:
screenshot of my pdf
Here, as you can see the word नाबालिगों is incorrectly spelled. Why? How do I fix this?
see here :
tFPDF
This class is a modified version of FPDF that adds UTF-8 support
or this :
UFPDF
that adds UTF-8 support
but you could move to TCPDF
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.
I cannot convert this font (TrueType Unicode) for use in tcpdf. I'm using UTF-8 encoding
https://dl.dropboxusercontent.com/u/14964998/chamberssansoffc.ttf
https://dl.dropboxusercontent.com/u/14964998/chamberssansoffcb.ttf
https://dl.dropboxusercontent.com/u/14964998/chamberssansoffcbi.ttf
https://dl.dropboxusercontent.com/u/14964998/chamberssansoffci.ttf
This font works fine on me website - renders Chinese, Polish, German, Romanian characters.
I would be grateful for help.
To see all UTF-8 encoding in tcpdf I will prefer use freeserif font.You can see a good example in tcpdf, example number 8.
Try this
$pdf->SetFont('freeserif', '', 12);
Now if you don't want to use freeserif, you can convert this font by tcpdf example by use this line.open tcpdf example folder, than open example __001, after 31 number line anywhere just past this code.Here make sure your path directory.Than run this code.After run go to font folder.You will get all your desire file.
$fontname = $pdf->addTTFfont('/wamp/www/tcpdf/arial/arialuni.ttf', 'TrueTypeUnicode', '', 32);
As far as i know you can`t use ttf directly but you can search for font converter tcpdf or use this tool: http://fonts.snm-portal.com/. Helped me.
It looks like you are trying to load the fonts remotely. That wont work with TCPDF because it needs to write the the font directory in order to create the pseudo-files for the PDF. Try adding them locally:
$fontname = $pdf->addTTFfont('/path-to-font/chamberssansoffc.ttf', 'TrueTypeUnicode', '', 32);
Also, you have to make sure that the font folder is writable on the server to allow TCPDF to create the pseudo-files.
Hope this helps!
I am using TCPDF to generate multilingual content PDF in PHP. I am using TCPDF and using font 'cid0jp' but It is forcing user to download language pack for adobe reader.
Is there any way to generate multilingual pdf without enforcing user to download any langauge pack?
Yes, there's a way. I just had the same issue. Why Adobe Reader is asking for the language pack i don't know.
But i know that the best way to create multilingual PDFs is to use the Arial Unicode MS-Font which is included in windows. That's the font with the most characters according to wikipedia!! But there's no Bold or Italics. You can buy a Arial Unicode Bold from http://www.linotype.com/en/817674/ArialUnicode-family.html#.
I use the Arial MS Unicode-Font with chinese, japanese, cyrilic. For western languages i use the normal Arial so i have italics and bold.
An other possibility is to use for each language a own font which is made for this language.
To make the Arial MS Unicode to work with tcpdf follow the steps on the answer of this Question: Creating PDFs using TCPDF that supports all languages especially CJK
I hope i could help...
Use html2pdf for multilingual.
I tried with this and it worked for me.I developed site for (English/Japanese)
Used font arialunicid0 for multilingual.
require_once('Classes/library/html2pdf.class.php');
//$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8');
$html2pdf->setDefaultFont('arialunicid0');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$filename = $filename .'_'.date('Ymd');
$html2pdf->Output($filename.'.pdf','D');
It download file with Japanese text.
Only problem I facing here with file name.
IF I pass Japanese character for file name it downloads file with blank name.