Bosnian characters in FPDF - php

I have an bosnian string $string = "Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul."
I used "Write" function of fpdf http://www.fpdf.org/ but all "č" characters become to "è"
$pdf->Write (6, iconv('UTF-8', 'CP1250//TRANSLIT', "Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul."));
How can I fix it? thank so much!

Something like this should work:
require_once 'fpdf181\fpdf.php';
require_once 'fpdf181\makefont\makefont.php';
MakeFont('C:\\Windows\\Fonts\\arial.ttf','cp1252');
$pdf = new FPDF();
$pdf->AddFont('Arial','','Arial.php');
$pdf->AddPage();
$pdf->SetFont('Arial','',16);
$pdf->Write(6,'Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul.');
$pdf->Output();
Try to change the encoding to cp1250 or ISO-8859-2.
Source: http://www.fpdf.org/en/tutorial/tuto7.htm
If all this should fail then try to use UTF-8: http://www.fpdf.org/en/script/script92.php

Personally I would not use UTF-8 in my PDFs because the file size will big for me. I use font embedding in this case to avoid a big file size.
The FPDF class can produce documents in many languages other than the Western European ones: Central European, Cyrillic, Greek, Baltic and Thai, provided you own TrueType or Type1 fonts with the desired character set. UTF-8 support is also available.
For the UTF-8 support you have to use tFPDF which is based on FPDF. tFPDF accepts UTF-8 encoded text. Please read all this instructions and then download the ZIP file on the bottom from this site.
Convertation to UTF-8:
You do not need a convertation to UTF-8 if you use instructions above (from link) and load a UTF-8 string from a file like follows:
// this file file must be saved in UTF-8 before:
$str = file_get_contents('Text-saved-in-UTF-8.txt');
In other case:
You have to use mb_convert_encoding and not iconv. For Bosnian (Latin) this is 'iso-8859-2'.
In yor case for:
$mystring = "Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul.";
You have to write:
$str = mb_convert_encoding($mystring, 'UTF-8', 'iso-8859-2');
Your PHP file must be saved in iso-8859-2 before (but not in UTF-8).
And then you use this in tFPDF.
Related answer from me: Serbian characters in FPDF

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.

Thai, Vietnamese language not supported in Excel

I have created an excel in which it has Thai and Vietnamese language. My problem is that it is showing these characters as question marks.
My code is below
$worksheet->write($i, 5, iconv("UTF-8", "ISO-8859-1//TRANSLIT", html_entity_decode($text)), $mainquest);
I have also tried all the other ISO standards. I put ISO-8859-1 for french language support. I also tried the mb_convert_encoding but no progress.
Is there any solutions for this?
The encoding charset is not the same as French for Vietnamese and Thai
For Vietnamese (Windows)
- charset=windows-1258
For Thai (Windows)
-charset=windows-874
so for Thai:
$worksheet->write($i, 5, iconv("UTF-8", "windows-874",html_entity_decode($text)), $mainquest);
and for Vietnamese:
$worksheet->write($i, 5, iconv("UTF-8", "windows-1258",html_entity_decode($text)), $mainquest);
If switching the library is an option I'd suggest to use phpexcel. It is UTF8-based, which means you shouldn't get into trouble with character encoding at all (if everything else is neatly set to utf-8 in your workflow – db,files, webserver). Never had any problems with this library so far, while having generated spread sheets with all kind of special characters.
you must use UTF-8 encoding for this problem

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

Support for norwegian characters in FPDF

I'm using fpdf to create some pdf's from a HTML-form.
Everything is working fine apart from the norwegian characters ÆØÅ doesn't work. They simply don't show. Because I am making this for norwegians, those characters are very important to make it useful.
How can I add support for ÆØÅ?
Please try iconv:
Standard FPDF fonts use ISO-8859-1 or Windows-1252. You can try iconv to change character encoding.
Example:
$str = iconv('UTF-8', 'windows-1252', $str);
And if you can change your PDF generation code then please look at mpdf : UTF-8 multilingual
Hope this help!

converting non-unicode, non-english content to unicode

I've a text content in "xyz" language.
<p style="font-family:xyz;"> eWvS³: kmwkMnsâ kq¸Àt^mWmb KmeIvkn kocoknsâ aq¶mw]Xn¸v </p>
// It will not display correctly as font is not embedded.
here the font xyz (xyz.ttf) is non unicode.
Now I want to convert that "XYZ" (xyz.ttf) font text to unicode "PQR" (pqr.ttf) font
Simply, a non-unicode Chinese (non_uni_chinese.ttf) to uniocode Chinese (uni_chinese.ttf)
how can I make it possible using php. any help?
You must do this "character by character".
It's mean you must replace every character in "non-Unicode Chinese" font to Unicode font.
I don't know much about Chinese, but in Vietnam, they use this way:
Write a string that contains "non-Unicode" font by an Unicode font, and these characters will not display correctly. For example: Ñaây laø Tieáng Vieät <- this is a non-Unicode Vietnamese write with an Unicode font.
Replace "character by character". For example: Ñ = Đ; aâ = â; aø = 2;...
Then we have this result: Đây là Tiếng Việt.
Of course we don't do it step-by-step, we use a software called "Unikey" to do this.
And I'm sure that there is a software to do that in Chinese. The point here is you must "do" it again in PHP.
Here come something can help you: http://www.pinyin.info/tools/converter/chars2uninumbers.html
Good luck.
Generated output should use one encoding. It's not proper solution, but anyway, for converting string to different encoding you should use iconv function http://www.php.net/manual/en/function.iconv.php

Categories