0

I have been searching for an answer to this problem now for several weeks. I also previously tried to research this a few years ago to no avail.

Problem Summary:

My company has developed a web-based data analytics suite for a major beverage distributor. They have recently asked for a feature that allows the user to print or download a visually pleasing version of the rendered app as a PDF. I have had no luck in finding a solid, controllable, or reliable method to do this. I was hoping the stack community might be able to point me in the right direction.

Current Tech Stack:

  • Plack servers
  • Perl base on the Dancer framework
  • Standard web dev front-ends: HTML5, CSS3, Javascript, Jquery/UI
  • Client is using IE9/10 and Chrome.

Attempted Solutions Summary:

Obviously I started with the window.print() and tried to control what printed using classes and a specialized print.css but the output was still awful.

I looked in to pdfmachine and pdfbox and even contacted Adobe's acrobat development team directly to see if they had an out of the box solution our company could purchase. I was informed that such a product would be counter intuitive to their desired business model of putting an acrobat subscription on each client computer rather than a single server side application.

I have extensively searched the stack articles but did not feel that the articles I found covered what I was looking for.

At present, I am all out of ideas and am hoping somebody out there has had better luck at this than I have.

tl;dr = I need a pdf version of the rendered output of a complex reporting app.

Thanks for your time stack, I appreciate it.

Dr.Avalanche
  • 1,944
  • 2
  • 28
  • 37
Joshua Fort
  • 54
  • 1
  • 6
  • Perhaps [this SO question](http://stackoverflow.com/questions/9029365/mechanize-print-to-pdf), and the question it's linked as a duplicate of, could be helpful. The answer to the original question suggests using [WWW::Mechanize::Firefox](http://search.cpan.org/~corion/WWW-Mechanize-Firefox-0.74/lib/WWW/Mechanize/Firefox.pm) to connect to the site and generate a PNG. You could then convert that to PDF. – ThisSuitIsBlackNot Feb 10 '14 at 21:31
  • These stories look pretty helpful. I will begin investigating and report back. Thanks for the prompt response! – Joshua Fort Feb 10 '14 at 22:21

3 Answers3

1

A solution I have used in the past is to use PhantomJS running on a server to generate the PDF for download/email. Usually if the content is sensitive the server (that handles authentication) would provide a single use viewing token that is then passed to a PhantomJS process. It loads the URL with the viewing token then saves as a PDF.

Further info on Phantoms screen cap API can be found here on GitHub. https://github.com/ariya/phantomjs/wiki/Screen-Capture

Morgan ARR Allen
  • 10,556
  • 3
  • 35
  • 33
  • I am also investigating PhantomJS now. Thanks for pointing it out! – Joshua Fort Feb 10 '14 at 22:21
  • The method I've used is basically using Phantoms `Server` module to accepts requests. In my case I want to create a report off a GUID. It then requests an internal URL that doesn't require authentication to load the report and saves it to PDF to be emailed. You could also send this back to the browser (or a link to) for downloading. – Morgan ARR Allen Feb 10 '14 at 22:49
0

Is it something you can create in Perl using PDF::API2 or PDF::Create? You can load and modify and existing PDF (handy if you want standard headers and footers), and then insert the relevant content. The learning curve can be a bit steep, but simple reports should be easy enough.

See PDF::TextBlock and PDF::Table too - they are great little helpers.

Mike
  • 21,301
  • 2
  • 42
  • 65
0

Consider this service http://pdfmyurl.com/ . I try to use many perl modules, but they dont satisfy my problems.

perlito
  • 55
  • 6
  • I had found several services similar to this one. The problem is that it would require my users to api out to a 3rd party system. The data being displayed in the app is proprietary information and is confidential, so we need to keep the conversion system in house. – Joshua Fort Feb 13 '14 at 23:19