I have a project to use spipu/html2pdf package to generate pdf documents, this pdf need to support all variety of languages
I am trying to use freeserif font as default font, the freeserif font support most western languages, including Hindi and Arabic. But seems not support Japanese/Korea/Chinese. Does anyone know which font under TCPDF support all
all variety of languages? or how to can support all variety of languages using spipu/html2pdf package. Thanks.
Here is my test code:
$html2pdf = new Html2Pdf('P', 'A4', 'fr', true, "UTF-8");
$html2pdf->setDefaultFont('freeserif');
$content = nl2br($PageTag);
$html2pdf->writeHTML($content);
Related
I need to work on using open source/free font with TCPDF. Specifically Noto or Code2000. But it doesn't work well, and displays other font instead. Basically I want to have nice font, works with multiple language, and support bold and italic.
I did Google about this, but no luck.
Tried the following method:
TCPDF font converter.
ttf2ufm (https://github.com/PhenX/ttf2ufm)
Did anyone ever succeed? Are there another workaround on this?
Thanks!
I had the same problem.
make sure you have these 2 lines set
$pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$lg['a_meta_charset'] = 'UTF-8';
$pdf->setLanguageArray($lg);
$pdf->SetFont('dejavusans', '', 8);
dejavusans Font has the required data for several languages.
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.
Can someone put together a clear and concise example of how you can create a PDF using TCPDF that will support text strings from any language?
It appears there is not a single font that will support all languages. I'm guessing the font would be too large?
I assume the correct way would be to detect the language of the string and dynamically set the font type to a compatible font. If this is the case then it gets very complex in detecting the language for each string.
Most languages are supported if you use the "freeserif" font. However it does not support CJK fonts. I've tried many fonts (kozminproregular, cid0jp, cid0kr, cid0jp, stsongstdlight) to get support for Chinese, Japanse, and Korean, but none of them seem to support all three languages.
This worked out perfectly for me. Thank you!
To make sure, the generated PDF file will not get to big, use FontSubsetting - I have a 10 page PDF generated with only a few Lines of chinese (Names on Diplomas)
$pdf->setFontSubsetting(true); => PDF File slightly bigger 925kb vs 755kb without the chinese names
if you use
$pdf->setFontSubsetting(false); => PDF File size as about 17.5 MB ...
Managed this problem by making my own font from arial ms unicode with these steps:
In a temporal script put and execute this
1. put a copy of ARIALUNI.ttf in fonts folder under tcpdf installation (i've taken my copy from windows\fonts folder.
2. make a temporary script in examples folder of tcpdf and execute it with this line:
$fontname = $pdf->addTTFfont('../fonts/ARIALUNI.ttf', 'TrueTypeUnicode', '', 32);
3. set the new font in your pdf generator script:
$pdf->SetFont('arialuni', '', 20);
Now the pdf should be showing correctly CJK characters.
Hope this helps so many people.
I just tried Etiennez0r's solution, and it didn't work for me. Needed to make a minor modification as below:
$fontname = TCPDF_FONTS::addTTFfont('../fonts/ARIALUNI.TTF', 'TrueTypeUnicode', '', 96);
I setting:
$fontname = TCPDF_FONTS::addTTFfont(FCPATH . 'TCPDF/fonts/ARIALUNI.ttf', 'TrueTypeUnicode', '', 32);
.......
// set font
$pdf->SetFont('dejavusans', '', 14);
$pdf->SetFont('cid0cs', '', 14);
Export Japanese is working well
I'm using a pdf generator class(TCPDF) to generate a pdf file from some html. The problem is that that html text has some utf8 and unicode characters. This class has support for those characters.
I've made the settings and all works just fine on localhost. But when I upload the files to my web host, I get a white page. I use exacty the same code.
If I delete the unicode and utf-8 characters it works. I've copied the script but on the server it is not working. It is there a php setting for handling those characters? Something in php.ini maybe? Thank you
As well as making sure that PHP has the mbstring extension installed, make sure you're setting PHP's encoding in the script with mb_internal_encoding('UTF-8'); or in php.ini.
You also need to make sure that the font being specified in TCPDF has support for UTF-8 characters. I've had big problems with this over the years and eventually just decided to use the Freesans and Freeserif fonts that are bundled with TCPDF.
Also when instantiating the TCPDF class make sure you have set the 4th and 5th parameters of the class constructor. If omitted they should default to TRUE, UTF-8 but I always specify to make sure.
$pdf=new PDF('P', 'mm', 'A4', TRUE, 'UTF-8');
$pdf->SetPageOrientation('P', FALSE, $margin_v);
$pdf->SetMargins($margin_h, $margin_v, $margin_h, TRUE);
// USE BUNDLED freesans FONT FOR DECENT UTF-8 SUPPORT
$pdf->setFontSubsetting(TRUE);
$pdf->SetFont('freesans', '', 11);
Check the docs for the TCPDF constructor
I've got a "little" problem with Zend Framework Zend_Pdf class. Multibyte characters are stripped from generated pdf files. E.g. when I write aąbcčdeę it becomes abcd with lithuanian letters stripped.
I'm not sure if it's particularly Zend_Pdf problem or php in general.
Source text is encoded in utf-8, as well as the php source file which does the job.
Thank you in advance for your help ;)
P.S. I run Zend Framework v. 1.6 and I use FONT_TIMES_BOLD font. FONT_TIMES_ROMAN does work
Zend_Pdf supports UTF-8 in version 1.5 of Zend Framework. However, the standard PDF fonts support only the Latin1 character set. This means you can't use Zend_Pdf_Font::FONT_TIMES_BOLD or any other "built-in" font. To use special characters you must load another TTF font that includes characters from other character sets.
I use Mac OS X, so I tried the following code and it produces a PDF document with the correct characters.
$pdfDoc = new Zend_Pdf();
$pdfPage = $pdfDoc->newPage(Zend_Pdf_Page::SIZE_LETTER);
// load TTF font from Mac system library
$font = Zend_Pdf_Font::fontWithPath('/Library/Fonts/Times New Roman Bold.ttf');
$pdfPage->setFont($font, 36);
$unicodeString = 'aąbcčdeę';
$pdfPage->drawText($unicodeString, 72, 720, 'UTF-8');
$pdfDoc->pages[] = $pdfPage;
$pdfDoc->save('utf8.pdf');
See also this bug log: http://framework.zend.com/issues/browse/ZF-3649
I believe Zend_Pdf got UTF-8 support in 1.5 - What version of Zend Framework are you running?
Also - what font are you trying to render with? Have you tried alternate fonts?
Have you made sure that you are setting the character encoding as this example from the manual?
// Draw the string on the page
$pdfPage->drawText($unicodeString, 72, 720, 'UTF-8');
If you're stuck into having to use a bold font, maybe try one of the other bold fonts?
Zend_Pdf_Font::FONT_COURIER_BOLD
Zend_Pdf_Font::FONT_TIMES_BOLD
Zend_Pdf_Font::FONT_HELVETICA_BOLD
ZF v. 1.6, TIMES_BOLD (as I understand thats the only way to make text bold?)