PHP: How to render PDF reports containing charts? - php

I want to create PDF reports containing some pie/bar charts. I have to create them with my PHP web app and cannot use commandline tools. For the frontend I use flot. However, I don't know how to get these charts in a PDF, because my project is constrained to PHP.
How do I generate images from my charts to render a PDF?
Update: The solution has to be open source since my project will be open source, too.
Best,
Stefan

Of course you won't be able to use a javascript charting solution to generate graphics to be used directly in a PDF. What you could do however, is use a PHP charting solution to create the graphs. Provided you have GD support built-in (it usually is) you could use pChart or libChart to create GIF/PNG charts you can embed within your PDF.
And for PDF generation I would personally recommend using TCPDF.

Can you use PDFLib ?
http://php.net/manual/en/ref.pdf.php
http://www.pdflib.com/pdflib-cookbook/graphics/fill-pattern/

Related

Is there any way to export fusion chart in excel using custom export buttons?

I am using fusioncharts/3.2.4 library for rendering charts on webpage. I searched on google but could not find an answer to how can I export fusion charts in excel/PDF using custom export buttons?
Note: I dont want to use any builtin library aswell.
I searched and found that fusioncharts/3.2.4 does not provide native excel export functionality.
Thanks in advance.
i'm working with the 3.11.3 and doesn't appear any at the XLS but the PNG and PDF work well.
but this can answer your question: i found something that can help you
You can explicitly use action based framework for this and export the excel in the way you want. I have used Apache POI for this, but you can use any of the library for this.
If you want the image of this chart as a part of excel, you can create the string of chart with the use of any backend technology and embed it with a static html content, making static html file.
Test the file by opening in browser, if it is same as that of your application expectation.
Then use 'wkhtmltoimage-0.12.5-1.exe' to generate graph image with proper wait time, and embed this generated image inthe new sheet of the excel file.

Highchart render in pdf generated using PHP mPdf

Can anybody suggest me what should I do ?
I am generating the PDF report and in the report, I have to print the high chart graph. As high chart uses the javascript which will not execute in PDF file, So I have to create the graph on the server.
I read many posts, they suggest me that i have to create the image of that graph, but my question is how will I create the image to that graph ?
You could try using server-side "browser" or JS engine to generate your graphs; there are tools that can be used for that.
For that purpose I used those:
PhantomJS: some quirks regarding header/footers but a nice lot of examples on website
WkHTMLToPDF: highly customisable, but I had trouble setting timeouts properly so graphs are fully generated before PDF output
But there are others.
As Preuk says, phantomjs is a good choice and what I use, here's a guide to it on the Highcharts site: http://www.highcharts.com/news/56-improved-image-export-with-phantomjs
It can be fiddly to get going but works well once you get it up and running.

Print Highcharts in pdf format

Is it possible to Print the highchart as a PDF using DOMPDF or any other PHP Html pdf generators?
Version 2 of Highcharts includes PDF generation. The Highcharts client side will export an SVG string, and there will be server modules based on Batik that do the conversion to PDF. You can try it out at Link.
This component will only convert the chart itself. If you want to convert the whole webpage or parts of it, check out the server library with the name of wkhtmltopdf (read WebKit HTML to PDF). It converts the charts too.
Take a look at their latest announcement about generating images on the server.
Once you save the images, you can add them to a pdf using libraries such as tcpdf
Please familiarise yourself with the included exporing module and parameters which can be used http://api.highcharts.com/highcharts#exporting

Easiest way to generate chart to an image server-side (to be embedded into PDF)?

I am using Highcharts.js to generate nice looking charts, I am trying get these charts embedded into a PDF, so would need the process to generate the chart into an image done server side.
Can anyone suggest the simplest method ideally without any need for the command line?
You can use JpGraph to generate graphs with PHP and save as an image:
http://jpgraph.net/
You can generate PDFs or any other office format (PDF, ODT...) including charts of any king with Docxpresso API. The API allow you to generate the document and the chart in one shot. You donĀ“t need to generate the chart and then integrate it in the document. The API is free to use for non comercial use and you can install it in any server using PHP.
http://docxpresso.com/files/html52pdf.zip

creation of pie and bar charts in php website

HI. I wanted to know if we could create pie and bar charts based on info from the database on a php website. I want to grab some information from the database and show it as an image so better analysis. Is there anyway to do this?
Also, If i am using fpdf to generate pdfs from php and mysql, can i also design pie charts in that pdf and show it as an image in that?
You could use the Google Chart API
I'd recommend using tcpdf instead of fpdf. fpdf was pretty good, but is no longer actively developed. tcpdf is.
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
As for the graphs there are many libraries displaying image graphs like http://jpgraph.net/
or client side JS libraries that will create flash graphs like ExtJS
JpGraph is a pure php library for generating graphs which outputs an image. I'm not familiar with fpdf but if it can embed images then this solution should work out.
http://jpgraph.net/
I'm using ChartDirector (not free) and FPDF to do this (today as a matter of fact).
ChartDirector can write the chart to a file, which I stick in /tmp. Then I import the file into the PDF file. Then I delete the file from the disk. Then I do it twenty more times with different data.
I'm sure any chart library that can write to disk will work. With FPDF, you can set the size of the image you import. So here's a trick: create the chart image twice as large as you need it and tell FPDF to place it at the size you want. This way, you'll get an image in the PDF file at around 144 dpi (assuming your library exports at 72dpi for the screen). You'll have a PDF that doesn't look as pixelated when zoomed in, and it will print better.
Check out this article on A List Apart for a method using the Raphael javascript graphics library. It demonstrates how to take a generic HTML table and replace it with a cross-browser, dynamic, scalable pie chart. The same could probably be done for a bar chart.
The advantage of this method is semantically correct markup - useful for users without JavaScript, as well as bots and screen readers.

Categories