Slow PDF generation with PHP+DomPDF

后端 未结 1 1486
南旧
南旧 2021-01-16 08:27

I spent a while dealing with a really slow PDF generation process using DomPDF. After a lot of fiddling and googling, I eventually got a solution which I thought I\'d post i

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-16 09:23

    SOLUTION:

    After a lot of googling, trial and error, looking up a lot on Stackoverflow (none of the articles I found were really helpful), I figured out that it was bootstrap that was causing the issue.

    I was using bootstrap for very basic layout management and I realized that linking the whole library (even the minified one) into the view that was sent to dompdf was overkill, but I didn't want to re-write the view file.

    So, I took a different approach: Get the CSS definitions for the specific classes (6, maybe 7) my view was using and inline them in a

    and remove bootstrap altogether from the view.

    retesting, the results were astonishing: A 100 purchase order (100-page) PDF (less than 60 kB in size) which took between 30-60 seconds to be generated and streamed to the user before the change, is now being generated in less than half a second, which confirmed that linking bootstrap produces a HUGE overhead on dompdf which is probably unnecesary in 99% of use cases.

    Hope this helps someone. It took quite a few days of work to figure this out.

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