take time to generate a pdf with mPDF Kartik for Yii2

Asked

Viewed 450 times

0

I am generating a pdf with 41 and this taking about 3 minutes, would be able to generate this file faster?

follows the code:

    $pdf = new Pdf([
        // set to use core fonts only
        'mode' => Pdf::MODE_CORE,
        // A4 paper format
        'format' => Pdf::FORMAT_A4,
        // portrait orientation
        'orientation' => Pdf::ORIENT_PORTRAIT,
        // stream to browser inline
        'destination' => Pdf::DEST_BROWSER,
        // your html content input
        'content' => $content,
        // format content from your own css file if needed or use the
        // enhanced bootstrap css built by Krajee for mPDF formatting
        'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
        // any css to be embedded if required
        'cssInline' => '.kv-heading-1{font-size:14px}',
        // set mPDF properties on the fly
        'options' => ['title' => 'Relatório de plano de contas'],
        'defaultFontSize' => 3,
        'marginLeft' => 10,
        'marginRight' => 10,
        'marginTop' => 30,
        'marginBottom' => 11,
        'marginHeader' => 6,
        'marginFooter' => 6,
        // call mPDF methods on the fly
        'methods' => [
            'SetHeader' => [$header],
            'SetFooter' => ['<p style="text-align: center;font-size: 8px;">Documento emitido pelo Mono Sistemas Gestão Empresarial. Todos os Direitos Reservados © www.monosistemas.com.br</p>'],
        ]
    ]);
    $pdfName = 'PLANO_DE_CONTAS-_' . date('d-m-Y') . '.pdf';

    Yii::$app->response->format = Response::FORMAT_HTML;
    Yii::$app->response->setDownloadHeaders($pdfName, 'application/pdf');

    return $pdf->render();

}
  • 41 pages? Try upgrading PHP to a more modern version (especially version 7, which has not yet been released in its production version). Or analyze if there are any features in your hosting that are limiting you (mainly processor and RAM).

  • So I think the problem is the formatting of the pages, when I take out the css, the time decreases a lot. But it still gets very high (1min). The server is local so it’s no problem with hosting,.

  • In this case there is probably nothing to do. Maybe PHP 7 will improve, but it should not improve enough. I see no alternative but to replace it with another tool less intensive than mPDF or a native tool like Wkhtmltopdf.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.