KoolReport's Forum

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

Export To PDF button #304

Open Jeff Baker opened this topic on on Jun 4, 2018 - 5 comments

Jeff Baker commented on Jun 4, 2018

In your example here: https://www.koolreport.com/examples/reports/export/sakila_rental/index.php you have a button to export to pdf. In your code example here: https://www.koolreport.com/packages/export I do not see where such a button is set up.

How would I go about triggering the pdf download to browser via a button click (via a button of my choice)?

KoolReport commented on Jun 4, 2018

Hi Jeff,

The way it works is like this. When you click to export button, it is actually a link that direct you to the export.php page that put in the same folder of index.php. In the export package we will call the $report->run()->export()->pdf()->toBrowser("export.pdf"). This command will generate pdf and send to browser to download. You may get the code from our example that you have downloaded.

Please let me know if you need further assistance.

Regards,

KoolPHP Inc

Jeff Baker commented on Jun 4, 2018

I see, so if I want to have a single export page, I would just assign the $report object to a session variable correct? IE:

$_SESSION["report"] = $report;

And on export.php I would have

$report = $_SESSION["report"];
$report->run()->export()->pdf()->toBrowser("export.pdf")
KoolReport commented on Jun 4, 2018

No, you should not. If you want to be in a single page, the link will send to current page with parameter index.php?action=export for example. And in the index.php, you check $_GET["action"] and if it has value "export", you run above code.

The reason you should use $_SESSION like above is that the report contain many data and saving to session will consume a lot of memory.

Jeff Baker commented on Jun 4, 2018

If I save the basic report object, isn't that relatively small? I would think it would only be an issue if I try to save the resulting values from $report->run.

The reason I am trying to do this is that I may have parameters that are different from the defaults.

KoolReport commented on Jun 4, 2018

You may do so if it is necessary for you. Here is another example List orders of customers. In this example, we allow user to choose a customer then we will list all of their order. Later the customerid will be sent to export.php to export all the list of customers. it seems close to your case.

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

Export