Alexxosipov
Alexxosipov

Reputation: 1234

Dompdf generating pdf very slow when I use it with laravel

I got an html file. When I used dompdf "standalone" (no laravel there) (I mean only install dompdf via composer), it works as fast as it can (generate 50kb html + a lot of images there for 5 seconds only). But when I installed dompdf on my laravel app and adjusted my html to blade template, it working much slower (same html rendered for 40-50 seconds!!!). This depends on the images, when I got no images in my html template, it works fine.

Rendering images with blade and paths like this: {{public_path('pdf/img/12345.jpg')}}. What should I do to avoid this problem?

My controller's code is:

public function create(Request $request) {
    $pdf = new Dompdf();
    $html = View::make('pdf.template')->render();        
    $pdf->loadHtml($html, 'UTF-8');
    $pdf->setPaper('A4', 'portrait');
    $pdf->render();
    $filename = "Hi!";
    return $pdf->stream($filename, ["Attachment" => false]);
}

But dd($html) works very fast, and I dont understand, why images makes rendering so slow on laravel app, but it works fine on standalone app.

Upvotes: 2

Views: 7356

Answers (1)

Kenneth Poulsen
Kenneth Poulsen

Reputation: 949

Bootstrap is the cause of this, or similar with a lot of css classes.

More details, and why, can be found here: Slow PDF generation with PHP+DomPDF

Upvotes: -1

Related Questions