Exporting charts and maps to PDF

Overview

Sometimes it very important to have an ability to be able to generate a PDF report, a lot of Paperless office use PDF as a standard for documents, AnyChart allows to create PDF reports with charts, using "Save as Image" feature.

This feature requires server side scripts that are capable of creating PDF documents.

to top

How it works

When AnyChart finishes rendering a chart on client-side it can create a PNG or JPEG image and send it to server or application, PNG or JPEG image data is sent in base64 encoding and server should decode it and output to the server.

Any server side script that is capable to create PDF document can now use this image data to create PDF document with chart.

Also, you can embed a JavaScript that will replace all Flash charts on the page by images (which should be generated by server-side script), and then pass full HTML page to PDF export script, that allows to convert HTML to PDF.

to top

Sample of Save as PDF functionality

Sample below demonstrate how PDF export image can be implemented. They use LGPL PHP html2ps and html2pdf Library to create PDF documents, but you can use any other library of your choice.

In AnyChart, you can configure context menu item that allows to save chart as PDF, you can set where converter script is located and image sizes (for example to fit letter page format). Image type defines image format to be passed to script - this allows to use PNG or JPG (if your converter doesn't support one of these formats).

XML Syntax
Plain code
01 <settings>
02   <pdf_export url="http://www.anychart.com/products/anychart/saveas/pdf/PDFSaver.php" file_name="anychart.pdf" use_title_as_file_name="false" image_type="jpg" />
03 </settings>

 

to top

Export chart as PDF

All samples in AnyChart Gallery and Live Previews in documentation have "Save as PDF" button (you can also see "Save as PDF" menu item on chart right-click), this button invokes method that passes image to server and server-side script generates PDF document that is passed back to chart.

You can download script that is used at AnyChart.Com to generate PDF documents from the link below, please note that this script is written on PHP and uses 3rd party html2ps and html2pdf generation library.

Please review PDFSaver.php before deploying PDF Saver on your server.

Download PDF Generation Scripts: PDFGeneration Script.

to top

Export HTML Page with chart as PDF

To export page with Flash Charts to PDF you need to replace all flash content by images.

In the sample below JavaScript is used to replace all charts on the page by images, images are generated by server-side PHP script, you need to have PHP 4.3.0 or higher enabled web-server with GD support to watch this sample in work.

Place all files from the sample to your server and open autosave.html file.

Download sample: Replace all charts by images Sample.

 

to top