KoolReport's Forum

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

Export package: PDF does not start download at first call #1125

Closed Sergio de Sousa opened this topic on on Oct 10, 2019 - 6 comments

Sergio de Sousa commented on Oct 10, 2019

Hi

I am having this serious issue with exporting to PDF: the download dialog does not start, most of the time, at the first "click" to invoke export. I have to stop that transfer or close the tab that opens, then try again and then the download dialog will open within seconds. But not at the first try! Though, very occasionally, it works.

I have no idea if it generates an error because I see no error on the apache error_log, neither on screen with display_errors turned on at php.ini. I have debug level turned on on the logs.

Here's my code snippet for my 'export.php':

<?php

require_once "Genius.php";

$prefix = $_GET['prefix']; 
$cityprov = $_GET['a']; //$_SESSION['cityprov'];
$compr = 	$_GET['b']; //$_SESSION['Comprehensive'];
$summa = 	$_GET['c']; //$_SESSION['vehicle_summary'];
$demog = 	$_GET['d']; //$_SESSION['demographics'];
$geogr = 	$_GET['e']; //$_SESSION['geography_summary'];
$edge  = 	$_GET['f']; //$_SESSION['e'];
$magna = 	$_GET['g']; //$_SESSION['m'];
$gtx   = 	$_GET['h']; //$_SESSION['g'];
$getstr = '&a='.$citypr.'&b='.$compr.'&c='.$summa.'&d='.$demog.'&e='.$geogr.'&f='.$edge.'&g='.$magna.'&h='.$gtx; 


$report = new Genius(array(
    "db_prefix"=>$prefix,
    "cityprov"=>$cityprov,
    "compr"=>$compr,
    "summa"=>$summa,
    "demog"=>$demog,
    "geogr"=>$geogr,
    "edge"=>$edge,
    "magna"=>$magna,
    "gtx"=>$gtx)
);


$report->run()
->export('GeniusPdf')
->pdf(array(
    "format"=>"Letter",
    "orientation"=>"portrait",
    "margin"=>array(
          "top"=>"0.5in",
          "bottom"=>"0.5in",
          "left"=>"0.5in",
          "right"=>"0.5in"
      )
    //"zoom"=>2
))
->toBrowser("Genius-report.pdf");

This unfortunately has a very HIGH priority for my client who considers this a STOPPER. My licence is Pro, so I am using the export package that is bundled. Also, PhantomJS is installed with my server version (Linux).

If I am not able to provide a solution for this issue, my client will either drop the project entirely or I'll have to resort to make these reports export by using FPDF or something as horrible as that :( Please help.

Please let me know if you want me to send you all my code related to exporting, but provide an email to do so because there's some confencial info that I am not free to post here in the forum.

Thank you,

=Sergio

KoolReport commented on Oct 11, 2019

The issue seems strange issue, we have not encountered before. But from what you describe, I guess that phantomjs take much time to get start. When you hit export, the Export will start prepare resource and start running phantomjs to render report. It take sometime for phantomjs to start. After the export is done, phantomjs will exit. However, if you call immediately after that, phantomjs will start faster as it may be cached by system. That's why the second time is very fast.

Let check if your server is too busy with other tasks or the cpu and ram of server could affects. Another solution is you try our CloudExport package. The cloud export package connects to our chomeheadless.io service which use chrome headless( instead of phantomjs) to export PDF. The dedicated service could solve your issue.

Sergio de Sousa commented on Oct 11, 2019

I suspected this much. Do you know any way I can speed up starting phantomjs in linux?

Also: my report template actually includes several tables and charts. Would this work well with your cloud reporting? What do I need to change in my code to use the cloudexport?

Thank you.

KoolReport commented on Oct 12, 2019

Using CloudExport is kind of the same, please refer to our documentation to get token key from chromeheadless.io and run the exporting code.

Sergio de Sousa commented on Oct 12, 2019

On your documentation page for the Export package, it says that I can opt to run the export to PDF using Chromium (headless Chrome), but there's something odd with the explanation: the links provided still point to PhantomJS? See below:

''' Installation Node.js and Chromium # In case you want to use chrome headless to export to PDF, please follow these steps:

Download the export package and unzip it. Copy the folder export into folder koolreport/packages If you have admin right, download node.js from this link for your operating system https://nodejs.org/en/download/. Then install it on your server and go to folder koolreport/packages/export and run the following command line: npm i puppeteer If you can't install node.js on your server, please download the following portable node.js for your operating system: Window: phantomjs-2.1.1-windows.zip Linux: phantomjs-2.1.1-linux.zip MacOs: phantomjs-2.1.1-macosx.zip Then extract it to koolreport/packages/export All done! Enjoy exporting your report with KoolReport now. '''

So, is it possible to try and substitute Chromium to export the PDF? Can you help me understand how to do it?

As a last resort I will indeed try the CloudExport as suggested, but I'd like to experiment this other possibility first.

Thank you.

David Winterburn commented on Oct 14, 2019

Hi Sergio,

Headless chrome support in Export package is experimental. To use it you will need to install either Chrome browser or nodejs' Puppeteer package which includes Chromium on your server. For our case, it's really troublesome to make it run in a lot of server environment so we focus on building a cloud service where we could make it works fluently. Thanks!

Sergio de Sousa commented on Oct 15, 2019

Ok, thank you. I changed to CloudExport as per your advice. Just for the record, I had to add page-breaks in a different way than what's been said here, I needed to add a style where I wanted the break:

<div class="text-center" style="page-break-before:always;"

and not just as mentioned:

<div class="page-break"></div>

The latter did not work with CloudExport.

I am closing this issue now, but I still want to implement headless Chrome on my server. I'll ask for your help when I am ready to do so (I'll install it myself and will come to you when done).

Thank you for your help.

=Sergio A.

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
bug
help needed

Export