0

This may be asking too much, but here goes...

I have a single page web application with dynamic content -- charts and maps (from other servers) in div tags, and so on. I would like to generate a PDF from this page, such that it reflects the page's current state.

I know I can reproduce the contents of the page in a separate html page and feed that into a PDF generator, but I was hoping for a less labor intensive way. To this end, are there any PDF libraries that can walk the DOM and construct a PDF page?

EDIT

I know of similar questions on this site, but none of the answers solved them; rather, each answer required reconstructing the page prior to sending it to PDF. The problem is I have a single page web application and would like to avoid doing that or re-architecting my application just so I can get PDF printing.

R. Barzell
  • 666
  • 5
  • 24
  • possible duplicate of [Create printable PDF from html dom](http://stackoverflow.com/questions/9749372/create-printable-pdf-from-html-dom) – clockworkgeek Mar 25 '15 at 22:50
  • As an alternative approach, look into "print to pdf". Some systems (Linux) have this as standard whereas others can get this as a printer driver. The advantage is it works from any program not just browsers. – clockworkgeek Mar 25 '15 at 22:52
  • @clockworkgeek yep, I saw that question, but I posted mine because none of the answers actually covered how to do it. Rather, the suggestions still required reconstructing the page. – R. Barzell Mar 26 '15 at 00:19
  • @clockworkgeek "print to pdf" might do the trick. My deployment platform is CentOS, so as long as I can send the PDF back to the user who is using the application remotely, this can definitely work. I'll do some legwork -- thanks. – R. Barzell Mar 26 '15 at 00:20
  • http://www.cloudformatter.com/CSS2Pdf is Javascript that walks the browser DOM, extracts it and cleans it up abit and sends to a remote server for formatting. The remotes server uses XSL to convert the XML obtained from the DOM to XSL FO and onto PDF (or any other supported format). – Kevin Brown Mar 26 '15 at 01:01
  • @KevinBrown Unfortunately, CSS2Pdf is glitchy (it chokes on Google Maps and glitches with FusionCharts), but otherwise, it's what I'm looking for. If you wish to submit this as an answer, I'll accept it, since it does technically what I asked for :) – R. Barzell Mar 30 '15 at 21:54
  • I would say yes ... and .... post a question in the Stackoverflow group css-to-pdf. The team and I would be happy to examine. We know Fusioncharts pretty well, surprised we did not test that one. Google Maps is a whole different animal usually killed from cross-site scripting but we can look at it. – Kevin Brown Mar 30 '15 at 23:54
  • @KevinBrown IIRC, the PDF shows the chart fine, but on the application, the chart is black, like it got highlighted. Clicking elsewhere clears the color. Anyway, got the answer, accepted and up-voted. I'll see about submitting a more detailed report. If those issues can be cleared up, this would fit the bill perfectly! – R. Barzell Mar 31 '15 at 21:29

1 Answers1

2

cloudformatter.com/CSS2Pdf is Javascript that walks the browser DOM, extracts it and cleans it up abit and sends to a remote server for formatting. The remotes server uses XSL to convert the XML obtained from the DOM to XSL FO and onto PDF (or any other supported format).

As you are now looking for Fusioncharts and Google maps, post a question in the Stackoverflow group css-to-pdf. The team and I would be happy to examine. We know Fusioncharts pretty well, surprised we did not test that one. Google Maps is a whole different animal usually killed from cross-site scripting but we can look at it.

Kevin Brown
  • 8,805
  • 2
  • 20
  • 38