Do you have any free .Net managed code for converting DocX to PDF?

Soul_Master picture Soul_Master · Aug 31, 2009 · Viewed 8.8k times · Source

In my web project, I use DocX file type for containing report template. I need to convert DocX file type to PDF. Do you have any .Net managed code for doing that?

I know several ways for solving this question. But it isn't managed code and free like the following items.

  • Word 12.0 Object Library To programmatically save a Word 2007 document as either a PDF document or an XPS document. But it requires installing Office 2007 on server.

  • Print by using some free PDF printer like PDFCreator. But I need some program for open DocX on server like Office 2007. It's very bad idea.

  • Convert by free convertor program. But result isn't perfect.

  • Use framework like XF Rendering Server. It's very good idea but it isn't free.

  • Create all document content in PDF Api like iTextSharp. But I must try hard for creating nice document.

  • Or create template document with other file format that can export it to DocX and PDF file format. Moreover, end-users should easily edit this file. If you know, please tell me.

Thanks,

Answer

Jerry Bullard picture Jerry Bullard · Oct 18, 2009

I do not have code for converting DocX to PDF, but it appears your requirement for DocX is not firm. Your last bullet says:

Or create template document with other file format that can export it to DocX and PDF file format. Moreover, end-users should easily edit this file. If you know, please tell me.

I read this to mean you want to be able to create a template document, fill it with data and covert it to PDF, yet allow the template to be maintained, right?

Solution: XSL-FO

XSL-FO is a W3C standard like HTML and can be transformed by a number of open source and commercial products into PDF, WordML, XPS, PS, PCL, SVG, TIFF, etc. I have used this to deliver hundreds of thousands of documents per month, both online as PDFs and offline (things like bulk check printing).

To get you started, here is the W3C page for XML-FO. There is a lot of good information there, including a list of software (both open source and commecial) down the left side. I have personally used two commercial products called IBEX PDF Creator and XEP by RenderX. Both are excellent products, and there is a 100% managed C# implementation to get to PDF called FO.NET up on CodePlex. I have not tried this, but it should satisfy your "free" criterion.

There are a number of ways you can edit the template for documents to be created in XSL-FO. Typically this template is XSLT that you apply to your XML data, but this is not a requirement. I have built these by hand, but it is a bit of a learning curve. You can start with a document in XSL-FO and fill in sections of it with code, just as you could HTML. The good news is that there are a number of XSL-FO editors out there. The bad news is that none I know of are free, but several of them are cheap and you may find something that meets the free criterion with a bit of Googling. However, one option is that you can convert from Word using a stylesheet (commercial & free).