0

Hello I have an html page that through php pulls reports about sales and puts them in charts and graphs. It works great however I am looking for a way to convert a div box into a pdf so whoever is using the sight can print specific graphs and charts that are in selected div boxes. Is there a simple way to do this or is this unfeasible?

Thanks!

T Neate
  • 403
  • 2
  • 6
  • 18

1 Answers1

2

There are lots of answers here merely talking about making a PDF. That's the easy part - the hard part is finding an engine that renders the CSS well.

This question has been raised before, and the issue doesn't lie with feasibility (it's very possible and there are lots of solutions), but they vastly differ on their capabilities to translate CSS into PDF. Many just completely fail altogether.

From my research it looks like WKHTMLtoPDF is your best bet, as it uses a full WebKit engine to render the HTML first, then translate that into a PDF (I found a tutorial in addition to the docs).

The downside? It's command-line, so you'll need to engineer a solution involving either python or php to execute the program. Here's the PHP manual on executing a program.

Edit:

I have personally used FPDF before, which is a surprisingly light-weight solution with a caveat that you have to provide it with all of the HTML (edit:) line-by-line, rather than being able to use the browser-rendered result of a HTML page (a result that would include a rendered chart). I'm providing it merely as a suggestion and to help you work out where you can go from here, but it's not directly applicable to your complex CSS/chart problem.

Community
  • 1
  • 1
Singular1ty
  • 2,577
  • 1
  • 24
  • 39
  • 1
    "HTML by scratch" is very easy in 2015. especially with sites like codebeatify.org – Alexander Dixon Aug 04 '15 at 01:28
  • @AlexanderDixon Good point. More my point was that FPDF has its content generated line-by-line, rather than using the resulting page (complete with Javascript-generated charts). – Singular1ty Aug 04 '15 at 01:31
  • 1
    Have you looked at http://www.cloudformatter.com/CSS2Pdf for samples like http://www.cloudformatter.com/CSS2Pdf.SVGCharts.HighCharts. Combine this demo http://www.cloudformatter.com/CSS2Pdf.Demos.MultiSelect with the charts and you have multiselect div chart printing. – Kevin Brown Aug 04 '15 at 03:27