HTML2PDF - Add a font

alexdu17200 Posted messages 1579 Status Member -  
alexdu17200 Posted messages 1579 Status Member -
Hello everyone, I'm using the HTML2PDF library to generate a .pdf file from HTML content.

What I would like is to apply a font to this content so that it is taken into account in the generated PDF.

I have 2 fonts in .otf format (one is the Light version, and the other is the Bold version).
I have tried in vain to declare it in CSS (
@font-face
...) and apply it to the <page> tag.

I read that I should use the AddFont() and SetFont() functions, but I must have made a mistake in my code.

$html2pdf->AddFont('Mapolice', '', 'font/Ma Police_Light.otf'); $html2pdf->SetFont('Mapolice','', 12,'','');
which returns an error stating that the SetFont function is not defined.

If anyone has a solution or can provide me with help, I would greatly appreciate it. Thank you.

1 answer

alexdu17200 Posted messages 1579 Status Member 841
 
Resolved for adding the font, but now I have another problem.
My font in my .pdf has made it so that each character is glued to the others (there is no space between the characters)

To add the font to HTML2PDF:
- I converted my font from .otf format to .ttf format on a site whose name I have forgotten.
- I then converted my font (.ttf) again to .php and .z so that I could use it with HTML2PDF (via this site http://www.fpdf.org/makefont/
- Next, I downloaded the 2 font files generated in the previous step
- I placed these 2 files on my server in the folder
html2pdf/_tcpdf_5.0.002/fonts/
- Then, it was done in the file that generates my .pdf
require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php'); $html2pdf = new HTML2PDF('P', 'A4', 'fr'); $html2pdf->addFont('MaPolice', '', dirname(__FILE__).'/html2pdf/_tcpdf_5.0.002/fonts/MaPolice.php'); $html2pdf->setDefaultFont('MaPolice'); $html2pdf->WriteHTML($content); 

And there it is, my font is set as the default for this .pdf file

As I said at the top of this response, my font is implemented BUT I have hardly any spacing between the different characters
I can still adjust the character width by modifying the MaPolice.php file, and I can achieve this
But, we agree that this is not readable.

I consider this question resolved to ask another one regarding how to modify MaPolice.php.
5