views:

526

answers:

5

Hey,

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.

+2  A: 

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

Mark Redman
Mmm. But if the content to hide is a section within a page, this becomes a little more difficult.
Paddy
You could add a page that does not contain that section, then programatically adjust another page (or both) then replace it when you need to?
Mark Redman
A: 

I would consider using creating HTML files from templates and turn them into PDF with Prince. Prince is very flexible and crating HTML files from templates is much easier then creating PDF files directly.

Tomas
We currently do something like this (using activePDF) and it's a bit on the slow side.
Paddy
A: 

I would use iTextSharp. I create all kinds of PDF files based on different templates and iText has worked the best for me. It is a very powerful control and can manipulate pdf files in just about any way.

I'm not sure that iText can handle your third requirement. I know that it can create a pdf from a html file. Maybe use what Tomas posted and create the pdf with iText.

Brian
A: 

Why need the template files in the pdf format? With the dynamic that you want it is a bad format for reporting template. Use a reporting software that also output as pdf. Your designers can create the templates very easy with a GUI. You will find many reporting solutions here on stackoverflow.

Horcrux7
+1  A: 

We've used http://www.dynamicpdf.com/, for projects like this and have been pleased with the outcome. They have a PDF WYSIWYG designer tool that you can use to build out the layout template of your PDF, along with the tool to merge the template with your data based on field to column mapping. This saves hours of hand coding each element of a given PDF. It supports page headers and footers and deals with the complexities of page breaks.

James