Converting docx to pdf using openxml and pdfcreato

2019-04-15 01:58发布

问题:

I need to convert docx to pdf file in server. I have seen PDFCreator will do, based on below link(http://sourceforge.net/projects/pdfcreator/).

I need some suggestions on this as listed below:

  1. can i use PDF Creator in server side.
  2. without creating word object, can i convert docx to pdf with openxml by using pdfcreator API.

Please give me reply soon.

回答1:

You can use docx4j.NET to convert a docx to XSL FO, and from there, to PDF. Or, indeed, to any of the other output formats supported by Apache FOP.

See this sample.

docx4j.NET is an IKVM'd DLL of docx4j, an ASL v2 licensed open source project.



回答2:

I think you're trying to do two different things here. OpenXML works with the DOCX file - Word is not used in any way in this case. PDFCreator appears to pretend to be a printer and when Word "prints" to it, it generates a PDF file.

Because you say you want to convert DOCX to PDF on the server, I am assuming you do not want to use Word. So your best shot, if you want all free software, is to use OpenXML to read the file and then call iText to create the PDF. Your code is basically going to convert from reading the OpenXML content to feeding that to iText.

Keep in mind that there are a lot of complexities to this. It's not just read a paragraph from OpenXML, write it to iText. You have to pass to iText all paragraph and run properties as well as any applied styles, lists, etc. The rules for how to indent the first line of a paragraph alone are quite complex.

If you're open to commercial software there are a number of products that can easily do this. If so, add that to your question and I'll list those (including my company).