Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP-font-lib must either be installed via composer or copied to lib/php-font-lib

Tags:

php

dompdf

i'm trying to convert some html to pdf. After some google search i find dompdf but when i try to convert i retrieve

PHP-font-lib must either be installed via composer or copied to lib/php-font-lib

This is what i'm trying to do:

require 'pdf/dompdf.php';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");

How can i solve? Thanks!

like image 856
Jayyrus Avatar asked Nov 17 '12 15:11

Jayyrus


2 Answers

Dompdf moved recently to Github, and we also added Composer support. For this, we removed the reference to the required external library php-font-lib.

Note: If you are using composer to install dompdf (and php-font-lib), you need to put define("DOMPDF_ENABLE_AUTOLOAD", false); in dompdf_config.custom.inc.php. This will then allow composer to autoload php-font-lib which is installed through dompdf's composer.json file. Otherwise, you may still get an error. (See this issue)

If you are not using composer and want to use the latest edition of dompdf with this library: (source)

  • Get the latest dompdf release from Github and extract it into a directory.
  • Download the library release also from Github
  • Create the dompdf/lib/php-font-lib/classes/ directory.
  • In the zip file, take the contents of the src/FontLib/ folder and paste that into your newly created directory.
like image 51
Fabien Ménager Avatar answered Nov 11 '22 09:11

Fabien Ménager


While my edit is being reviewed, I'll post the details here for the latest dompdf 0.6.1

If you are using composer to install dompdf (and php-font-lib), you need to put define("DOMPDF_ENABLE_AUTOLOAD", false); in dompdf_config.custom.inc.php. This will then allow composer to autoload php-font-lib which is installed through dompdf's composer.json file. Otherwise, you may still get an error. (See this Issue #636)

If you are not using composer and want to use the latest edition of dompdf, you will need to manually install php-font-lib: (https://stackoverflow.com/a/24505929/3854385)

  • Get the latest dompdf release from Github and extract it into a directory.
  • Download the library release also from Github
  • Create the dompdf/lib/php-font-lib/classes/ directory.
  • In the zip file, take the contents of the src/FontLib/ folder and paste that into your newly created directory.
like image 27
Loren Avatar answered Nov 11 '22 10:11

Loren