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!
Related
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
I am using Codeigniter to generate PDF in russian language using fpdf.
IN that I have pass string like 'Добровольческой Бригады, 19, оф.1' but it displays in pdf like 'ДÐ3⁄4брÐ3⁄4Ð2Ð3⁄4льчÐμÑ•ÐoÐ3⁄4Ð1 БрР̧Ð3аР́Ñ‹, 19, Ð3⁄4Ñ„.1' .
How can I make it proper?
Thanks
Standard FPDF fonts use ISO-8859-1 or Windows-1252. It is possible to perform a conversion to ISO-8859-1 with utf8_decode(): $str = utf8_decode($str); But some characters such as Euro won't be translated correctly. If the iconv extension is available, the right way to do it is the following: $str = iconv('UTF-8', 'windows-1252', $str);
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.
you need this:
iconv('UTF-8', 'windows-1252', html_entity_decode($str));
the html_entity_decode decodes the html entities. but due to any reason you must convert it to utf8 with iconv. i suppose this is a fpdf-secret... cause in normal browser view it is displayed correctly.
Actully, fpdf project FAQ has an explanation for it:
http://www.fpdf.org/~~V/en/FAQ.php#q7
Don't use UTF-8 encoding. Standard FPDF fonts use ISO-8859-1 or
Windows-1252. It is possible to perform a conversion to ISO-8859-1
with utf8_decode():
$str = utf8_decode($str);
But some characters such as Euro won't be translated correctly. If the
iconv extension is available, the right way to do it is the following:
$str = iconv('UTF-8', 'windows-1252', $str);
So, as emfi suggests, a combination of iconv() and html_entity_decode() PHP functions is the solution to your question:
$str = iconv('UTF-8', 'windows-1252', html_entity_decode("©"));
I'm pretty sure there is no automatic conversion available from HTML entity codes to their UTF-8 equivalents. In cases like this I have resorted to manual string replacement, eg:
$strOut = str_replace( "©", "\xc2\xa9", $strIn );
I have fix the problem with this code:
$str = utf8_decode($str);
$str = html_entity_decode($str);
$str = iconv('UTF-8', 'windows-1252',$str);
You can also use setFont('Symbol') or setFont('ZapfDingbats') to select the special characters that you want to print.
define('TICK', chr(214)); # in font 'Symbol' -> print a tick symbol
...
$this->SetFont('Symbol', 'B', 8);
$this->Cell(5, 5, TICK, 0, 'L'); # will output the symbol to PDF
Output: √
This way, you won't need to convert to ISO-8859-1 or Windows-1252 OR use another library tFPDF for special characters :)
Refer: http://www.fpdf.org/en/script/script4.php for font & character list
Has anyone of you ever used php_writeexcel (http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/)?
I would like to know if there is an easy way to enable utf-8 support. php_writeexcel exports html to Microsoft Excel documents, yet it can't display certain characters:
http://pastebin.com/AgVpph7F
Perhaps I could solve this with some php functions?
Thanks for your help!
For fields with special characters (eg french) I use utf8_decode() to get the special characters to show up correctly.
Php_writeexcel is a port of the Perl module Spreadsheet::WriteExcel. However, the port is from a time when Unicode strings weren't supported in the underlying Excel file format.
Later (2.xx) versions of Spreadsheet::WriteExcel have native support for Unicode but they haven't been ported to PHP.
As such you won't be able to handle Unicode strings with php_writeexcel.
It isn't a perfect solution, but iconv will convert some of those characters.
http://www.php.net/manual/en/function.iconv.php
Depending how you want the unsupported characters to be handled:
iconv('UTF-8', 'ISO-8859-1//IGNORE','ėčščįęščūųüó');
output: üó
iconv('UTF-8', 'ISO-8859-1//TRANSLIT','ėčščįęščūųüó');
output: ??????????üó
I'm getting characters in my PDF, i've stripped out \r\n \r \n \t, trimmed everything, decoded html entities and stripped tags. Nothing helps. The data is coming from a MySQL database.
Any help would be appreciated.
Check string encoding (with mb_detect_encoding) before adding to pdf, is it unicode string? Data in MySQL db can be in unicode but your db connection can use some another encoding.
Did you try using utf8_decode()?
http://php.net/manual/en/function.utf8-decode.php
You might be using a font that is not available.
Try something like this to determine its numeric value and replace it:
$str = 'Hello World';
echo str_replace(chr(ord('')), '[removed]', $str);
Output:
Hello [removed] World
Have you tried
$string = "testContainingSpecialCharsäöüöüäüß";
$pdf->Cell(0,0,$string);
What characters should have been displayed instead of those things?
FPDF doesn't support unicode characters, so that might be the cause of your problem. There's an extension you could try at http://acko.net/node/56, or alternatively you could switch to another PDF generator library (I recommend TCPDF).
Or you could try using iconv to convert the text from UTF-8 to a supported character set (ie. $str = iconv('UTF-8', 'windows-1252', $str);) if you want to stick with FPDF.
Looks like the result of what happens when you copy / paste text from Microsoft word. Does the PDF file contain text from a MS Word document by any chance? That might be your problem. There are some interesting comments for converting and stripping these characters in PHP on the PHP.net website: http://www.php.net/manual/en/function.strtr.php#39383
I am only presuming it is MS Word characters in your PDF file.