dompdf fails to load

后端 未结 7 703
谎友^
谎友^ 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 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");
    

提交回复
热议问题