KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Cloudexport PDF generation taking up to 1 minute to generate 1mb pdf. #2288

Closed George opened this topic on on Aug 18, 2021 - 1 comments

George commented on Aug 18, 2021

It's taking an unusually long time to generate a pdf with a size of 1mb. Upwards to 1 minute. Using DataTables built in pdf export button will generate the same report in just 1-3 seconds. I'm using "useLocalTempFolder" => true.

and I can see the time between the tmp folder zip 611d68b4231b8, 611d68b4231b8.zip being generated and the final pdf output to be around a minute.

Any advice on how I can speed things up?

this is my ReportPDF.view.php

<?php

use koolreport\datagrid\DataTables;

?>
<html lang="en-US">

    <head>
        <link rel="stylesheet" type="text/css" href="global-theme.css?ver=<?= ASSET_VERSION ?>"/>
        <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
        <?php
        echo $_SESSION['export_pdf_html_header'];
        ?>
    </head>
    <body>
        <style>
        .print_head {
            margin-bottom: 20px;
            margin-top: 7px;
            color: #666 !important;
        }
        h6{
            padding-left: 20px;
        }
        .print_title {
            font-weight: bold;
            font-size: 17px;
        }
        .titleInfo {
            padding-left: 20px;
        }
        .company_logo {
            height: 30px;
        }

        .column-left{ float: left; width: 33.333%; }
        .column-right{ 
            float: right; 
            width: 33.333%;
            padding-left: 450px;
        }
        .column-center{ 
            display: inline-block; 
            width: 33.333%;
            padding-left:175px;
        }
        .table th, .table td{
            padding: 10px 5px 10px 5px !important;

        }

        @media print{
        * {
            -webkit-print-color-adjust: exact !important;
        }   
            @page {
                size: landscape;
            }
        }

        #table_footer td:first-child{
            background: black;
            color: #374354 !important;
        }
        .table th,#table_footer td{
            background: #374354 !important;
            color: white !important;
        }
        .table-striped > tbody > tr:nth-of-type(odd) > td {
                background-color: #f9f9f9 !important;
        }

        </style>

    <input type='hidden' id='footer_value' name='footer_value' value='<?php echo $_SESSION['footer_value']?>'>
    <?php
        DataTables::create($_SESSION['data_table_array']);
    ?>
    <script>
        const footer_val = $('#footer_value').val()
        if(footer_val == 1){
            $('tbody tr:last').attr('id','table_footer');
        }
    </script>
    </body>
</html>

The $_SESSION['data_table_array'] is something like:

    $data_table_array = array(
        'name'       => 'reportTable',
        'dataSource' => $table_data,
        "cssClass"   => array(
            "table" => "display table table-striped table-bordered",
            "th"    => "reportTableHeader",
            "tr"    => 'reportTableRow',
            'td'    => "reportTableCell",
            "tf"    => 'reportTableFooter'
        ),
        "options"    => array(
            "ordering" => FALSE,
            "dom"        => 'rt',
        ),
    );

where $table_data is just an array.

Sebastian Morales commented on Aug 19, 2021

How many rows are there in your DataTables? Please try to change the engine to khtml like this and see if it's faster:

    $report->cloudExport("MyReportPDF")
    ->khtml($secretToken) //use wkhtmltopdf instead headless chrome 
    ->settings($settings)
    ->pdf($pdfOptions)
    ->toBrowser($filename)
    ;

Cloud export would almost always take longer time for a number of reasons:

1 . PHP client on your local server needs to retrieve the report page along with all of its resources (css, js, image, etc) and zip them to send to cloud server.

2 . Cloud server extracts the files and uses a headless browser engine (chromium, wkhtmltopdf, or phantomjs) to render the page including css styles, js execution, chart generation (if there is), etc to export to pdf.

3 . Cloud server sends the exported pdf back to your local server.

In your case I think step 2 took the most time if there're many rows. Rendering a long table with all of its css styles in headless browsers is slower and different from generating PDF data structure with limited styles and no chart. Some library like mupdf could generate tens of thousands of table rows in a fraction of time. Rgds,

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

CloudExport