dompdf fails to load

后端 未结 7 610
谎友^
谎友^ 2020-12-29 03:23

I am trying to get dompdf running on an in-house server. With the default config.inc.php settings, I get the following when running the equivalent of the demo \'Hello Wolrd\

相关标签:
7条回答
  • 2020-12-29 03:59

    I had almost the exact same problem. My code was working on my local dev machine - a Windows box - but then was failing on our production server - a Linux box

    The problem was that the "classes" directory was lower case (\app\Vendor\dompdf\lib\php-font-lib\classes) which windows did not mind - but Linux being case-sensitive did!

    Simply editing the following line in dompdf_config.inc.php solved the problem:

    require_once(DOMPDF_LIB_DIR . "/php-font-lib/Classes/Font.php");
    

    For consistency I renamed the directory with an uppercase "C" on the Windows box.

    0 讨论(0)
  • 2020-12-29 04:05

    The new version of dompdf doesn't work with 'composer install' or 'composer update'. It needs special versions of font libraries which might not always be the latest versions, so this might change in future. But you can find how to install it via dompdf's documentation. Dont know why the authors haven't hardcoded these font versions inside the composer.json, but anyways here is how to do it.

    Currently the easiest and best way of using the library is via git (taken from the official docs)

    git clone https://github.com/dompdf/dompdf.git
    cd dompdf
    
    git clone https://github.com/PhenX/php-font-lib.git lib/php-font-lib
    cd lib/php-font-lib
    git checkout 0.4
    cd ..
    
    git clone https://github.com/PhenX/php-svg-lib.git php-svg-lib
    cd php-svg-lib
    git checkout v0.1
    

    Then you can just do

    use Dompdf\Dompdf;
    $dompdf = new Dompdf();
    $dompdf->loadHtml('hello world');
    $dompdf->setPaper('A4', 'landscape');
    $dompdf->render();
    $dompdf->stream( "/path-to-save-pdf-file/sample.pdf");
    
    0 讨论(0)
  • 2020-12-29 04:10

    We will use dompdf in codeigniter BUT the file that I’v downloaded from GitHub doesn’t has all the files that we need. Is missing all the files of php-font-lib. So we had to download it and uploaded to the respective folder. So, to have dompdf working in codeigniter you might have to download it.

    See here http://www.digitalwhores.net/codeigniter/codeigniter-dompdf-master-and-php-font-lib/

    0 讨论(0)
  • 2020-12-29 04:11

    If you are using composer to install dompdf, you need to put define("DOMPDF_ENABLE_AUTOLOAD", false); in dompdf_config.custom.inc.php. This will then allow composer to autoload the php-font-lib as it is already installed. (See this issue: https://github.com/dompdf/dompdf/issues/636)

    If you are not using composer, see Mikepote's answer.

    0 讨论(0)
  • 2020-12-29 04:15

    This is a temporary issue after the DOMPDF project moved to Github. See the answers to this question. The easiest solution to get the complete package is to download DOMPDF 0.6 beta 3 from Google Code.

    0 讨论(0)
  • 2020-12-29 04:16

    If error is not corrected after doing what other answers suggest:

    In dompdf_config.inc.php, change line 332 to point to the actual location of your Font.php  file.
    mine was /php-font-lib/src/FontLib
    

    There is no CLASSES folder that was mentioned there.

    0 讨论(0)
提交回复
热议问题