Dynamic PDF generation from template

Paddy picture Paddy · Jan 26, 2010 · Viewed 19.8k times · Source

I've a requirement to be able to generate PDF's within our (ASP.net) application. We need to meet the following requirements:

  1. The text will be largely dynamic and must be added programatically.

  2. Ideally we'd like to base these generated documents off PDF templates provided by our designers.

  3. Some of the sections/pages may or may not be visible depending on certain conditions - ideally we'd like the content to 'flow' upwards to fill the space when something is removed.

  4. Some of the pages may need to repeat, depending on certain conditions.

  5. Some of the PDF templates will be out of our control (we're populating application forms supplied by third parties), so being able to read in a blank PDF and populate it would be good.

I've looked at iTextSharp and it seems to do most of these things (i.e. I can take a PDF, edit it to include form fields where we need to fill data and then use iTextSharp to read that in as a template and populate the data), however, I'm not sure how then to go about potentially hiding whole sections and/or repeating pages.

What I'm looking for here is a little advice from anybody who's been in a similar situation.


Small update here, we went with iTextSharp - it's a powerful tool, but does take a bit of learning, however it's quick, light, and does precisely what we want it to do.

However...

I would point out that the latest version is no longer really free (as in beer) - the license does not permit commercial usage. As a result, we now have a licensed version, but it's not shockingly cheap (and they don't publish a price list).

Answer

Mark Redman picture Mark Redman · Jan 26, 2010

There are various commercial components to do this. Look at: PDFLib (http://www.pdflib.com/), Tall Components (http://www.tallcomponents.com/) etc

I have use products from Tall components and can recommend them.

Some others are a lot more expensive.

ITextSharp as you've mentioned is quite good and can be used to add/remove external pages, in this can you could hide full pages by ommiting them, or replacing them with placeholder pages. iText can use existing PDF files or create blank pages.

From my personal experience, I have just dropped in images and text onto existing pages and added pages generated by a reporting tool when tabular data is required.

HTH