views:

819

answers:

3

I've been having a heckuva time with this problem, and there seems to be a lot of noise out there in search engines in getting to the bottom of it, so forgive me if I've missed a silver bullet out there.

The base need is that I have to generate a PDF document that has both static and dynamic elements. I started to do this by having a PDF template with all the static content, and then I wanted to inject various dynamic elements into it. The problem is that PDFs are not meant to be manipulated that way, and depending on the size of the dynamic text I put in there, might overflow text on other pages. I was using iTextSharp but can't get past this problem.

A possible fallback is to generate a DOCX, which I've done before, and then convert it into a PDF on the backend. The only libraries I've found to do this are paid apps (like Aspose). There are examples out there that convert to PDF without these libraries, but they seem to require a client-side application. I'm doing this via IIS.

To make a long story longer...are there free libraries that will convert a DOCX file to a PDF server-side without launching client applications to do so?

A: 

Saving Word 2007 Documents to PDF and XPS Formats

bahith
I had seen that out there, but it appeared to be meant for (and maybe only usable by) client Windows forms applications. Is that example possible server-side?
Chris
@Chris, possible- yes, advisable- no.
RichardOD
+1  A: 

There are a few choices here:

  • build a COM interop class that will perform read and 'Save As' functions on your .docx. The MSDN link you gave doesn't require to be run client-side, but rather have the Office assemblies in the GAC or in your ASP.NET's bin directory.

  • buy a third party component to do the work for you. Here's just one example with no guarantees.

p.campbell
+1  A: 

I'm not familiar with any good free ones, but we used Aspose.Words to achieve something similar to what you describe. We keep Word templates with static text and mail-merge fields. The templates can be regular Word documents, they don't have to be .dot templates. Mail-merge fields can be either single fields or repeatable data in tables so you can easily generate pretty complex documents without doing dynamic document editing. (Which is always an option)

Using Aspose for this was so friction free that I would suggest using Aspose unless the cost (which is significant) is a show-stopper. The support is also good which is always an added bonus.

There are always some caveats...

  • I would have liked more control over the PDF compatability of the generated PDFs. We had some issues with older clients reading the generated PDFs.
  • Mail-merge is not fun. Complex mail-merge expressions was time consuming to get right.
Kim Major