mike_hornbeck
mike_hornbeck

Reputation: 1622

How to generate page running on server as a PDF

The task is not easy, as I need to create a PDF version of a page after clicking a button. It has a complicated dom structure, with many elements positioned absolutely/relatively, and the data is dynamically loaded. I thought about using Phantom.js server for this task, as it enables generating PDF's but this introduces some problems ;

I also thought about generating it client-side but because of the complexity of the site it would probably take me many days to get proper representation of the page (as all the positioning values need to be recalculated to pts), and it has to be a generic solution.

Any other ideas how to solve this ?

Upvotes: 2

Views: 1183

Answers (3)

acorncom
acorncom

Reputation: 5955

What about POSTing the entire DOM to the server using Ajax, rending it there as a PDF (using phantomjs), sending back a server URL (and nonce) in a JSON response? You could then create a download link or just initiate the download automatically. Would that work?

Upvotes: 1

Alexis Pigeon
Alexis Pigeon

Reputation: 7522

What about using a PDF printer? Depending on your system, there could be a built-in PDF printer, or if using Windows, you can have a look at PDFCreator

Upvotes: 1

Vivian River
Vivian River

Reputation: 32410

I've looked at several tools to accomplish server-side PDF generation.

There is one called abcPDF (.net) from Web SuperGoo that I tried to use, but I consistently had problems with it not working.

There is another one which seemed to work much better called iText, available in both .net and Java versions. Depending on what version you use, it is available with AGPL, LGPL, and commercial licenses.

I wish I could tell you differently, but I don't know of any way to easily convert from HTML to PDF. Each of these libraries has an API that you must program against to describe what the document should look like.

Upvotes: 2

Related Questions