PHP - Highcharts - PDF

Asked

Viewed 1,006 times

1

I am using Mpdf to make some values that I have saved in SESSIONS in php become a report, so far so good, but the page that I want to turn into report has graphics Js, Highcharts, I don’t know how to export these charts directly to the report that will be in pdf.

Website: http://carboncal.org/view/brasil/

Steps: Click Carbon per filter(menu) >> Calculate Carbon >> WHRC

  • 1

    Include some source code of what you’ve done so we can help you

2 answers

2


Unfortunately mpdf does not support javascript, so for you to show a highchart in your pdf you will have to export it in image format.

An example of this would be:

var hightchart = $('#container').highcharts().getSVG(); // Pega o highcharts e transforma em SVG.

Send the result by ajax to php, and then include it in your mpdf:

$html = "Olha um gráfico: ". $_POST['hightchart '];

include 'lib/mpdf/mpdf.php';
$mpdf = new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output('exemplo.pdf', 'I'); 

Example: Transforming graphic into image

Documentation: Highcharts Chart.getSVG

  • My Chart is separated in the project, as I take his ID and take it to the Php code where the MPDF ? I must save the highchart variable with the values of my chart and it in my Php code, make the request via Ajax ?

-1

To generate PDF tries to use a library called wkhtmltopdf, it is an interesting project that transforms into PDF the page rendered by Webkit, Google rendering engine.

If the charts are empty, try disabling the highchart animations.

  • On the web ? how to integrate this to Php for example ? rs

  • You have to install wkhtmltopdf on the server, or check if it is already installed. Then use a PHP library to create the PDF files. Example: https://github.com/mikehaertl/phpwkhtmltopdf OBS: If you are using a PHP framework, check if there are any wkhtmltopdf modules available for it.

Browser other questions tagged

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