Yii TCPDF missing embed font in Corel Draw X6 - php

I'm using this extension in Yii:
http://www.yiiframework.com/extension/tcpdf/
I would like to write to a pdf file with an external font, for example this:
http://www.1001fonts.com/open-sans-font.html
Here is my code:
$pdf = Yii::createComponent('application.extensions.tcpdf.ETcPdf', 'P', 'cm', 'A4', true, 'UTF-8');
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor("Some Body");
$pdf->SetTitle("TCPDF Example 002");
$pdf->SetSubject("TCPDF Tutorial");
$pdf->SetKeywords("TCPDF, PDF, example, test, guide");
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AddPage();
$fontRegular = $pdf->addTTFfont(Yii::getPathOfAlias('webroot') . '/OpenSans-Regular.ttf');
$pdf->SetFont($fontRegular, "", 30);
$pdf->Cell(0,10,"Example",1,1,'C');
$pdf->Output("example_002.pdf", "I");
It works, I can read the pdf many programs, except Corel Draw 6X. When I'm opening the pdf it starts with a message of "missing fonts" and I can't replace them any other kind of fonts. Can anyone tell me how should I add the ttf font, or embed it into the pdf?
Thanks in advance!

So the problem is for Corel Draw . You have to Install the font.
1)Download your ttf font from here
2)Extract it and copy the font to C:\Windows\Fonts
3) Restart Corel Draw and make sure the new font is available by creating a text field and selecting the font.
Reference

Related

Is there any configurations required to show telugu unicode fonts in tcpdf?

I have to generate a PDF from php page contains html which includes unicode fonts (Telugu). Its showing perfectly when I print html code and while rendering to PDF using TCPDF, the unicode characters are distorting of letter formations.
I have copied the telugu font from google translators and added a telugu font into tcpdf lib.
$message = '<h2 align="center">ధన్యవాదములు -- శుభోదయం</h2>';
$fontname = $pdf->addTTFfont('E:\xampp\htdocs\ncs\svdn\flowers\tcpdf\fonts\mandali-regular.ttf', 'TrueTypeUnicode');
$pdf->SetFont($fontname, "",30, false);
$pdf->writeHTML($message, true, 0, true, 0);
$pdf->Output("Test.pdf", 'I');
The output in html is like below. And the same has to be printed in PDF too.
ధన్యవాదములు -- శుభోదయం
But in current issue, the above consonants are disjointed:
TCPDF doesn't support the OpenType layout features needed for Indic scripts to work.
mPDF supports several indic scripts - including Telugu specifically - however, so if you're not too far along in your project to switch, that would be my recommendation.
This code should work for instance (though I have not tested it) after installing mPDF with composer:
include 'vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf();
//I'm being a little lazy here and letting mPDF select the appropriate
//appropriate font.
$mpdf->autoScriptToLang = true;
$mpdf->baseScript = 1; // Use values in classes/ucdn.php 1 = LATIN
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML('<h2 style="text-align: center;">'.
'ధన్యవాదములు -- శుభోదయం</h2>');
$mpdf->Output('test_mpdf_lang.pdf');

TCPDF font not embadding, showing "..." on adobe reader

I added many fonts in TCPDF using this line of code
TCPDF_FONTS::addTTFfont('fonts/ArchitectsDaughter.ttf', 'TrueTypeUnicode', '', 96);
$pdf->AddFont("ArchitectsDaughter");
Many other font is working but, this one is not working.
When i opening this pdf into reader, it shows error like this
cannot extract the embedded font 'ArchitectsDaughter'. some character
may not display or print correctly.
I am importing svg file in pdf.
Here is the SVG file which i inserting in pdf, and you can get PDF from here and here is the font file.
Here is full code how pdf will generates.
$fileName='export';
$uploadPath = Config::get('constants.paths.uploads.images.base').'/'.$fileName.'.svg';
$pdf = new TCPDF();
TCPDF_FONTS::addTTFfont(dirname(dirname(dirname(dirname(__FILE__)))).'/vendor/font-awesome/fonts/ArchitectsDaughter.ttf', 'TrueTypeUnicode', '', 96);
TCPDF_FONTS::addTTFfont(dirname(dirname(dirname(dirname(__FILE__)))).'/vendor/font-awesome/fonts/Archivor.ttf', 'TrueTypeUnicode', '', 96);
$pdf->AddFont("Archivor");
$pdf->AddFont("ArchitectsDaughter");
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$pdf->ImageSVG($uploadPath, $x='', $y='', $w='', $h='', $link='', $align='', $palign='', $border=0, $fitonpage=true);
$filename = 'export.pdf';
$pdf->output($filename, 'D');
exit;
Other fonts working ok for me. Don't know what happening with some fonts.
What is the solution for this?
According to documentation TCPDF_FONTS::addTTFfont() adds the provided font permanently to the fonts folder and returns its name. So there is no reason to add it every time, but it is necessary to use added font with correct name.
// ...
$pdf = new TCPDF();
$fontArchitectsDaughter = TCPDF_FONTS::addTTFfont(realpath(__DIR__ . '/../../../vendor/font-awesome/fonts/ArchitectsDaughter.ttf'), 'TrueTypeUnicode', '', 96);
$fontArchivor = TCPDF_FONTS::addTTFfont(realpath(__DIR__ . '/../../../vendor/font-awesome/fonts/Archivor.ttf'), 'TrueTypeUnicode', '', 96);
$pdf->AddFont($fontArchivor);
$pdf->AddFont($fontArchitectsDaughter);
// ...
First set up the font via TCPDF_FONTS::addTTFfont() or by adding the necessary files in the fonts dir (convert the TTF file via a TCPDF font converter like http://fonts.snm-portal.com)
After that, activate the font:
$pdf->SetFont('FontAwesome','');
Then, write a unicode character with the writeHTML function, starting with &#x and ending with ;
e.g.:  for the f0c9 (bars) icon (http://fontawesome.io/icon/bars/):
$pdf->writeHTML('');

using italic Arial (embedded) in FPDI

I'm trying to output a pdf file with an italic text in Arial and using FPDI for that.
Since the arial.php and the arialbd.php (bold) are already existing, it's working fine.
Now I found a ariali.ttf on the internet, which looks good when I open the overview of that font (little window with the quick brown fox sentence). But when I use the font in FPDI, it looks like this:
http://i.stack.imgur.com/muTN7.png
Does anybody know, how to fix this?
Is it an ttf issue or where does that strange presentation come from?
Here my example code:
$pdf = new FPDI('P', 'mm', array(210, 297));
$pdf->SetAutoPageBreak(false);
$pdf->AddFont('Arial', 'I', 'ariali.php');
$pdf->AddFont('Arial', '', 'arial.php');
$pdf->AddPage();
$pdf->SetFont("Arial", "I", 16);
$pdf->SetXY(20,20);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(20,5,"This is an italic test text in Arial!");
$pdf->Output("test.pdf", "I");
EDIT:
test.pdf
Setasign's question gave me the hint to try to open the resulting PDF in another PDF viewer too than just in my browser (chromium on debian).
The GNOME document viewer Evince is showing a blank page and Adobe Acrobat on Windows is showing nice italic Arial text but giving the error (freely translated from German) "The embedded font "Arial-ItalicMT" could not be taken out. In certain circumstances, some characters won't be printed correctly"
I'm just using my example code and FPDI Version 1.4.4.
The problem was the converter I used to generate the .php and the .z file from an .ttf file.
Always use the makefont scripts, shipped with fpdf/fpdi or use the online makefont: http://www.fpdf.org/makefont/

How do you add custom fonts in TCPDF?

I would like to add a custom font to a pdf I'm generating using TCPDF. I might be missing something but the docs seem to be out dated. They are referencing the addTTFfont() function but I think it's been deprecated and no longer exists in the latest version of TCPDF.
I read that I need to convert the ttf file and put it in the fonts folder so I ran:
php/tcpdf/tools/tcpdf_addfont.php -i php/font/rumpelstiltskin-webfont.ttf
and it generated these files which are now in the fonts folder:
rumpelstiltskinwebfont.ctg.z
rumpelstiltskinwebfont.z
rumpelstiltskinwebfont.php
Then I tried to add the font:
$pdf->addFont('rumpelstiltskin');
$pdf->SetFont('rumpelstiltskin', '', 14, '', false);
but I'm getting an error:
TCPDF ERROR: Could not include font definition file: rumpelstiltskin
I figured out my issue, I was almost there.
Here is a step by step:
First convert your font using the tcpdf_addfont.php tool font in the TCPDF tools folder:
php/tcpdf/tools/tcpdf_addfont.php -i php/font/rumpelstiltskin-webfont.ttf
This will generate the required files and put them in the TCPDF fonts folder. Check the fonts folder and copy the name of the font, in my case it was rumpelstiltskinwebfont.
In your code set the font using the font file's name and write a line of text:
$pdf->SetFont('rumpelstiltskinwebfont', '', 14, '', false);
$pdf->Write(0, 'Fill text', '', 0, '', true, 0, false, false, 0);
That's it. Hope this helps someone. :)
Got this answer in another question and resolved for me. You just need to use the first parameter, the path of the font file. Worked with TTF and OTF fonts.
It generates a name string to use with $pdf->SetFont($fontname, '', $font_size);
Hope it helps.
The latest TCPDF version automatically convert fonts into TCPDF format using the addTTFfont() method. For example:
// convert TTF font to TCPDF format and store it on the fonts folder
$fontname = TCPDF_FONTS::addTTFfont('/path-to-font/FreeSerifItalic.ttf', 'TrueTypeUnicode', '', 96);
// use the font
$pdf->SetFont($fontname, '', 14, '', false);
For further information and examples, please check the TCPDF Fonts documentation page.
NOTE: Once the font has been converted, TCPDF no longer requires the TTF file or the above call to addTTFfont()!
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('rumpelstiltskinwebfont', '', 14); using the name of the file
Since TCPDF (version 6.2.6) you can use TCPDF_FONTS::addTTFfont directly instead of AddFont.
TCPDF makes three files out of the ttf and puts them into the directory "font" of TCPDF. Once these have been created, they can be used for all future PDFs.
Example:
First (for simplicity) I created a folder in the font folder of TCPDF with the name of the new font, in my example "arialuni" and copied my ttf of this font into it.
If I want to create my font files in a single separate file that does not use Composer autoload, I have to include TCPDF once and also specify the correct path to my ttf.
require_once('vendor/tecnickcom/tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$fontname = TCPDF_FONTS::addTTFfont('vendor/tecnickcom/tcpdf/fonts/arialuni/arialuni.ttf', 'TrueTypeUnicode', '', 32);

SVG to PDF conversion using TCPDF in PHP

I am trying to convert a SVG file to PDF file using TCPDF library in PHP. I have created a SVG file and use PHP to replace text and plan to render the resultant SVG file to PDF file.
Any idea, if TCPDF library supports SVG to PDF conversion. Any pointers in this direction would really help me.
You don't really need to replace text or render, Once you have created your svg file. All you just need to include tcpdf in your script and create its object like e.g.
require_once(DOCUMENT_ROOT . '/library/Lib/tcpdf/mypdf.php');
$this->pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$this->pdf->AddPage(); // Add page to pdf before addding content
//There are several other property need to be set on basis of your need
$this->pdf->ImageSVG('file/mySVGFile.svg', 15, 20, '', '', '',
'', '', 1, false); // 15,20 are co-ordinate to position graph in pdf
Once you added your content to your pdf, Last step comes is to download the pdf using .
$this->pdf->Output('my.pdf', 'FD');
Feel free to ask for anything you have any query in this code.
Try
$pdf->ImageSVG(VIEW_JS."graph_as_svg/".php", '', '', '210', '100', '', '', '', 0, false);

Categories