6

I am filling a word template with data from the database, using OpenXML sdk 2.5 and i need to export the result in PDF. I am currently using a server-side Interop approach but from time to time I get the exception:

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00020906-0000-0000-C000-000000000046} failed due to the following error: 80080005.

Is there any other free way I can convert .docx documents to .pdf?

Just code
  • 13,553
  • 10
  • 51
  • 93
  • 1
    OpenXML doesn't use interop. And OpenXMl sdk doesn't include any functionality for document conversions. – Flowerking Jan 28 '13 at 14:51
  • Is there anyway I can get this functionality of Interop (preferably not server-side)? –  Jan 28 '13 at 14:52
  • Check this code.. this is using word interop, need office installation on the server - http://cathalscorner.blogspot.co.uk/2009/10/converting-docx-into-doc-pdf-html.html – Flowerking Jan 28 '13 at 14:54
  • I am already using Interop but i get COMExceptions, i cannot rely on it. –  Jan 28 '13 at 14:56
  • 3
    Yes. interops not preferable for porgramatic usage on server side.. pdf is proprietary format of adobe, the conversion libraries available are all commercial as of I know. I am using sharepoint to do conversions but that has a drawback of having unexpected delays during the conversion process. – Flowerking Jan 28 '13 at 14:58
  • Can't you keep on with Word interop and handle the failures gracefully? You should try to serialize the requests to Word (1 thread, 1 process only can ask for conversion at any time) to minimize errors. Ok, it's not recommended, but it can work. – Simon Mourier Feb 01 '13 at 09:35
  • It works fine for a couple of days then suddenly I get the above error. And I am the only user testing it. Having in mind that there can be up to 10 users using it simultaneously, I cannot rely on it. I understand it is a security/access rights and i gave rights to the IIS_IUSRS and NETWORK SERVICE in anything MS Word related, in REGEDIT too, still i get the error sometimes, which is unacceptable for the type of the application i am developing –  Feb 01 '13 at 09:44
  • 1
    You have created the document using OpenXML SDK (as you stated), right? Now just conversion is the issue. You may install any free pdf (virtual) printer (bullzip.com/products/pdf/info.php) and simply open and print the document to PDF printer using Word interop assembly in invisible mode. – Khadim Ali Feb 12 '13 at 12:36

1 Answers1

0

I used the Apache POI-XWPF library to render the docx to pdf (sample app) after having tried a lot of other things. It may be good enough for your scenario, but there are some limitations if you want to use specific fonts etc.

sebug
  • 41
  • 2
  • 8