1

I am using HTML2PDF in Laravel 5.1 and I need to add two fonts. I've tried searching for answers but they don't work for me whenever I try them.

I have tried the following (based on searches):

  • Go to http://www.fpdf.org/makefont/ to generate .php and .zip files of my fonts
  • I found a thread that said to put the files in html2pdf\_tcpdf_5.0.002\fonts\ because it's the default directory for fonts in FPDF. I went to vendor\spipu\html2pdf to look for such directory but found nothing. So I just placed the generated files in public\fonts as well as the .ttf files.
  • I also added the following to my code: $cambria_path = base_path() . '\public\fonts\cambria.php'; $html2pdf->addFont('cambria', '', $cambria_path);

    However, this does not work. This is the error that shows up: TCPDF ERROR: Could not include font definition file: cambria

  • I also tried this one: $cambria_path = base_path() . '\public\fonts\cambria.ttf'; $cambria = $html2pdf->pdf->addTTFfont($cambria_path, 'TrueTypeUnicode', '', 32);

    but it says Call to undefined method HTML2PDF_myPdf::addTTFfont().

What am I doing wrong and how do I add at least one font (it would be better if I can add at least two though)? Thank you in advance.

CH123
  • 251
  • 1
  • 5
  • 15

1 Answers1

0

In your second try I think you are calling incorrectly:

INCORRECT:

$html2pdf->pdf->addTTFfont

That's why they saying undefined method.

CORRECT:

$html2pdf->addFont('fontname', 'fontname.php')
iDon'tKnoware
  • 111
  • 1
  • 7