I am using the FPDF library to generate a pdf, I want to write Hindi and Marathi text in that but it display's only English text. I tried adding 'Devnagari' fonts using makeFont.php but still it doesn't work.Below is my code that adds text to a pdf
$pdf->SetXY(0,210);
$pdf->SetLeftMargin(28);
$pdf->SetRightMargin(28);
$pdf->AddFont('mangal','','mangal.php');
$pdf->SetFont('mangal','',11);
$pdf->Write(2,'खालील आपली भाषा');
I hade the same problem some years ago. I used then tFPDF and it solved the issue.
You may want to try it? The tFPDF class-file and an example are provided there: http://www.fpdf.org/en/script/script92.php
Have a nice day
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 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'm generating some order confirmations using FPDF library, which works great. But now I need some Chinese characters in the document. I have searching for many hours by now and have found no workable solution. Is it possible supporting Chinese characters using FPDF or is there an alternative to FPDF which will support it?
All the characters are mixed with regular text and are stored in a MySQL database. The PDF document only show unicode when printing the Chinese characters.
There exist Chinese encoding formats like Big5 or GBK. However, more likely than not, the text you are trying to input is in Unicode. There exists tFPDF, which provides Unicode support. I will test printing the following traditional hanzi: 中國. This means China, for those reading who do not know.
// Remember to copy msjh.ttf to [path to tFPDF]/font/unifont/ directory
// Initialize tFPDF
require('tfpdf.php');
$pdf = new tFPDF();
$pdf->AddPage();
// Add a Unicode font like MSJH
$pdf->AddFont('MSJH','','msjh.ttf',true);
$pdf->SetFont('MSJH','',42);
// Output Chinese string to PDF
$pdf->Text(12,42,"中國");
// Output PDF document
$pdf->Output();
Another alternative is the Code200365k TTF
$pdf->AddFont('Code200365k','','Code200365k.ttf',true);
I use it for Chinese characters only as follows:
if (preg_match("/[\x{4e00}-\x{9fa5}]+/u", $my_value)){
$pdf->SetFont('Code200365k','',12);
}
$pdf->Cell(130,9,$my_value,1,1,'L');
$pdf->SetFont('Arial','',11);
I'm trying to make my text underlined in FPDF but it seems to be impossible... I'm not using HTML. I'm using an DejaVu unicode font, which supports UTF-8, and also its my first time working with the FPDF.
Is that even possible? Please give me some solutions.
Try this :
$fpdf->SetFont('Dejavu','U'); //Where "U" means underline.
See also (in german) http://www.fpdf.de/funktionsreferenz/?funktion=SetFont
See also (in english) http://www.fpdf.org/en/doc/setfont.htm
I am using xpdf to convert pdf files to text.
Below is the code used for it.
$content = shell_exec('pdftotext '.$filename.' -');
Xpdf is not able to convert few special fonts in pdf to text.
for example: bizarre font cannot be converted to text using xpdf.
Are they any alternative software which can convert all kind of fonts in pdf to text in PHP.
Maybe you should try the Poppler version of pdftotext if the XPDF version fails for your files....
However, take note of this fact, please: Not even Acrobat Reader can extract all cases of well rendered text on a PDF page to a text file...