DOMPDF doesn't work with external css file

后端 未结 2 881
说谎
说谎 2020-12-07 01:03

I\'m using Zend Framework and DOMPDF library. When I test it with inline css everything works perfectly. But when I tried to move css code to the external file rules are not

2条回答
  •  情书的邮戳
    2020-12-07 01:28

    @Jurian Sluiman is on the right track, though his answer did not help me, unfortunately.

    I had to spend some time in order to find the solution that worked for me, which was using DOMPDF::set_protocol():

    $dompdf->set_protocol(WWW_ROOT);
    $dompdf->set_base_path('/');
    

    WWW_ROOT here is a CakePHP constant pointing to the webroot folder of my application. Note that it has a trailing slash.

    The best part is that this seems like improper usage of set_protocol(). But I'm fine with that as long as it makes the CSS work.

    • https://github.com/dompdf/dompdf/search?q=set_protocol
    • https://groups.google.com/forum/?_escaped_fragment_=topic/dompdf/uBWdQbug_dM
    • http://code.google.com/p/dompdf/wiki/CSSCompatibility

    Hope this saves someone else few hours of time.

提交回复
热议问题