tcpdf truetype unicode font install - php

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!

Related

tcpdf with hindi unicode character

I am using tcpdf for writing PDF. I am facing weird issue with it. I am not able to write Unicode Hindi Character. 'तुम्हारे' like for this character its writing as ?????. Though I have taken UTF-8 as input.
$tcpdf = new XTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$tcpdf->addTTFfont(K_PATH_FONTS . 'ARIALUNI.ttf', 'TrueTypeUnicode', '', 32);
Second line has created .z,.ctg,.php files. BUt still my text is outputted as ???
How can I write it for Hindi Unicode Characters.
I started using this website instead of the ->addTTFfont feature: http://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
I found this to be a much more reliable way of adding fonts to TCPDF. It will create the necessary files to drop in the folder. These are the files that would be created through the addTTFfont method.
Instructions:
Visit the website found above
Convert the .ttf file through this tool
Save the files it gives you right to the tcpdf/fonts folder.
I also search for hindi font in TCPDF and found solution at last. we have to a file from : https://code.google.com/p/pyfpdf/downloads/detail?name=fpdf_unicode_font_pack.zip&can=2&q=
we don't have to include whole files. just include lohit_hi.ttf file in your fonts fonlder
and then
$pdf->addTTFfont(K_PATH_FONTS . 'lohit_ta.ttf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont('lohit_hi', '', 10 ,'true');

issue with TCPFT fonts

Is it possible to have Polish letters in TCPDF generated PDF => ążźśćłó? I used font which work in FPDF library named arial_ce, but with no result:
$fontname = $pdf->addTTFfont('tcpdf/tcpdf/fonts/arial_ce.ttf', 'TrueType', '', 96);
$pdf->SetFont($fontname, '', 14, '', true);
the same result was in using DejaVuSansCondensed font.
Delete the arial_ce.z, arial_ce.ctg.z and arial_ce.php files from your TCPDF font folder, and then change
$fontname = $pdf->addTTFfont('tcpdf/tcpdf/fonts/arial_ce.ttf', 'TrueType', '', 96);
to this:
$fontname = $pdf->addTTFfont('tcpdf/tcpdf/fonts/arial_ce.ttf');
(addTTffont doesn't overwrite an already existing font, even if you change parameters, that's why I mentioned deleting the ones already created.)
The defaults work better for this font. After doing this, I was able to use polish characters in PDFs made by TCPDF.
Edit: Oh, and of course, TCPDF should be using the same character-set that your source string is in. In my case that would be UTF-8.

can't display ¥ with TCPDF, but other kanji are okay

I'm using TCPDF to create PDFs that include Japanese characters. Using the TrueType font ArialUni, most characters are displayed correctly, except the yen symbol shows up as a square box instead of ¥.
Here's a snippet of the resulting PDF using ArialUni:
So I tried another font. Here's the same section of the resulting PDF using GT200001:
And here's the same section using Helvetica:
Here's the same section using GNU's FreeSans:
I would like that second line to show up as "(渋谷猿, ¥8,000)"
I'm not surprised that Helvetica and Freesans cannot render the kanji correctly, but I cannot fathom why the other two fonts can render the kanji, but not the yen symbol, which is much more common.
The web server creating the PDFs is LAMP running Ubuntu. I'm viewing the PDFs on OS X with Chrome (using its in-browser view). I've also tried downloading the PDFs with Firefox and displaying in Preview. I get essentially the same results: ArialUni and GT200001 don't display the yen symbol, while Helvetica and Freesans don't display the kanji (but do display the yen symbol).
I know I can use different fonts for different lines/cells of the PDF, but the kanji and yen symbol are on the same line.
How can I get the kanji and yen symbol to display in a single line using TCPDF?
Near the top of my PDF code, I load the font using TCPDF's addTTFfont();
$this->font = $this->addTTFfont(K_PATH_FONTS.'arialuni.ttf', 'TrueTypeUnicode', '', 32);
Here's the code I'm using to write the section of the PDF.
$pdf->SetFont('arialuni','',10);
$pdf->MultiCell(105, $remarks_height, $remarks, 'B', 'L', false, 0, '', '', true, 1, false, true, $remarks_height, 'T');
In this wikipedia article you can read some more about this character.
Basically, there are 2 different ways of writing this Japanese Kanji, as it happens with some other symbols. From accepted answer "I was using ¥, not ¥", we can see that he was using the 'occidental' or Unicode ¥ symbol, when he actually wanted to use the double-width character ¥.
Oh dear, I figured it out.
I was using ¥, not ¥. Sorry for being confused!!
What I have noticed with TCPDF is, it's all about fonts.
I tried to use it for 15 totally different languages with different writing style too and only font I am using is Arial UNICODE MS.
TCPDF has function which will convert that font into TCPDF friendly files, which are arialuni.ctg.z(70k), arialuni.php(447k), and arialuni.z (14M).
the functions are,
http://www.tcpdf.org/fonts.php
$fontname = $pdf->addTTFfont('/path-to-font/ARIALUNICODE.TTF', 'TrueTypeUnicode', '', 32);

Creating PDFs using TCPDF that supports all languages especially CJK

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

Specific fonts in TCPDF pdf

Can somebody tell me what i am doing wrong? I need Arial font in my pdf generated by TCPDF.
First I've tried to use that :
1) I got Arial from windows fonts caltalog and put it in TCPDF directory.
2) Next I wrote in script :
$fontname = $pdf->addTTFfont('../lib/tcpdf/arial.ttf', '', '', 32);
After that in tcpdf/fonts appears 3 files (arial.ctg.z , arial.php and arial.z). I thought that everything was ok but if in TCPDF i use this font by:
$pdf->SetFont('arial', '', 16);
Font in document is indeed arial but without polish specific sings (ąęłżńź)
I've tried also prepare font by yourself :
I downloaded ttf2afm and makefontuni.php script then in command line I wrote this:
ttf2ufm -a arial.ttf
php -q makefontuni.php arial.ttf arial.ufm
that command gave me also 3 files (arial.ctg.z , arial.php and arial.z) but final situation is the same like before.
I've admit that all data writing to pdf is in UTF-8 and TCPDF construct is like this :
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'utf-8', false);
I don't know what am i doing wrong. :(
If you want to use a custom font use this tool
https://www.xml-convert.com/en/convert-tff-font-to-afm-pfa-fpdf-tcpdf
when you get the generated files just move them to the /fonts directory and with the same name they have, set the font-name attribute.
No need to add any font, use the Dejavu Sans Font which has all the UTF-8 characters built-in and the TCPDF has it already..
$pdf->SetFont('dejavusans', '', 14, '', true);
http://www.tcpdf.org/examples/example_001.phps
$fontname = TCPDF_FONTS::addTTFfont(FCPATH.'/assets/css/fonts/arial-unicode-ms.ttf');
This is what I use to include custom font to TCPDF. You need only .ttf file of the font. Add it in folder on your choice on the server and run this code once. ( I run it first time on export ) Then you can comment this row and the font would be there.
In order to add it to the exporter you should add it as font with:
$pdf->addFont('your-font-name', '', 10, '', false);
And if you want it to be default:
$pdf->setFont('your-font-name', '', 10, '', false);
If you don't know what is the actual name of the font to use in PDF:
echo $fontname;
This would give you the specific name of the font to use in the exported file.
After you run that command once the TCPDF creates all the file needed in its font folder and it is ready to use from now on.
If you want to re-add the same font (modified) you need to delete your font files in tcpdf/fonts/your-font-name. and run this command again to re-add them.
Hm, are you sure your Arial has all UTF-8 characters?
I followed instructions here http://www.tcpdf.org/fonts.php
and it worked. What I had problems was that I was only able to add Regular Font - as soon as I added Bold or Italic and then change from one another, all characters turned to dots.
So at the moment I'm only using my Regular font and for Bold I use 'dejavusans' (thanks to Miro).
My code:
$fontname = $pdf->addTTFfont('/lib/tcpdf/fonts/myfont-Regular.ttf','TrueTypeUnicode','');
$pdf->SetFont($fontname, '', 8, '', true);
I think it will help you to fix the character issue.
$pdf->SetFont('freeserif', '', 12);
Above font-family which supports the UTF-8 characters.
I had the same error i was able to fixed it putting the next, after de line:
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
true, 'UTF-8', false);
$fontname = $pdf->addTTFfont('tcpdf/fonts/arial.ttf', '', '', 32);
$pdf->SetFont('arial', '', 16);`
Is better if you convert the font to ctg.z/z/php files.
You can convert ttf fonts with http://fonts.palettize.me and then put uncompressed result in fonts folder into tcpdf class.
Then you can add it with $pdf->SetFont('jameelnoorinastaleeq', 'BI', 20);

Categories