tFPDF - Hindi text spelling is incorrect in pdf - php

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

Related

Slovak characters in Fpdi

I'm writing a PDF exporter for a Slovak web page. My DB is UTF-8 encoding.
Some characters from the DB are converted correctly, some are not, here is the example:
input from DB: ôňúäéíáýážťčššľĽŠČĎŽŇÁÍÚĹŤÉŽŹÝ
output in PDF: ônúäéíáýážtcššlLŠCDŽNÁÍÚLTÉŽ´ZÝ
font used: Helvetica
Basic code for PDF write:
$pdf = new Fpdi('P', 'mm', 'A4');
...
$pdf->SetX(14);
$pdf->write(40, iconv('UTF-8', 'windows-1252//TRANSLIT//IGNORE', $invoiceDetails->getCompanyName()));
...
// return output for preview
return $pdf->Output('I');
I've tried at least 10 encodings but none of them was able to give me all characters.
Thank you for your help.
The standard fonts in FPDF only support cp1252 (aka windows-1252) encoding. So changing the encoding of your text to any other encoding doesn't change a thing.
You should prepare a special font with an ISO-8859-2 encoding and convert your text to this encoding before passing it to the methods of FPDF. The whole font generation process is described here.

INR Currency Symbol Add in fpdf

I want to add INR Currency Symbol in pdf file using fpdf. how to add INR Currency Symbol (Rupee) pdf file using fpdf.
See fpdf font dump documentation
http://www.fpdf.org/en/script/script4.php .
Here, No option to add rupee symbol (₹) so, u can use rupee symbol png image and integrate with fpdf.
$pdf->Image('rupee.png',8,10,-200);
Here is a way to print the rupee sign with FPDF:
Copy the cp1252.map file (located in the makefont directory) to cp1252+INR.map.
Open cp1252+INR.map in a text editor. Replace this line:
!A4 U+00A4 currency
with:
!A4 U+20B9 uni20B9
This will map the rupee sign at position 0xA4 (instead of the generic currency sign).
Choose a font that contains the rupee sign and use MakeFont() with the cp1252+INR encoding to convert it. Here I will use the Arial font that comes with Windows:
<?php
require('makefont/makefont.php');
MakeFont('C:\\Windows\\Fonts\\Arial.ttf', 'cp1252+INR');
?>
Copy the generated files (arial.php and arial.z) to the font directory.
Add the font in your script and use chr(0xA4):
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddFont('Arial', '', 'arial.php');
$pdf->AddPage();
$pdf->SetFont('Arial', '', 20);
$pdf->Write(5, 'Rupee sign: '.chr(0xA4));
$pdf->Output();
?>
I understand that this is pretty late but a simple solution to this issue would be to use tFPDF which is essentially an extension to FPDF. Using tFPDF, you can use the 'DejaVu Sans' font which supports the '₹' symbol along with most other currency symbols. This font comes in packed with the tFPDF as well, so you can literally plug it in and use it in your current system directly.
More information can be found here:
http://www.fpdf.org/?go=script&id=92
<?php
// Optionally define the filesystem path to your system fonts
// otherwise tFPDF will use [path to tFPDF]/font/unifont/ directory
// define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/");
require('tfpdf.php');
$pdf = new tFPDF();
$pdf->AddPage();
// Add a Unicode font (uses UTF-8)
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',14);
// Load a UTF-8 string from a file and print it
$txt = file_get_contents('HelloWorld.txt');
$pdf->Write(8,$txt);
// Select a standard font (uses windows-1252)
$pdf->SetFont('Arial','',14);
$pdf->Ln(10);
$pdf->Write(5,'The file size of this PDF is only 13 KB.');
$pdf->Output();
?>
Cheers!!

Jumbled Kannada fonts in pdf report using fpdf and php

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.

Issues with Chinese characters in FPDF

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);

tcpdf truetype unicode font install

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!

Categories