8

I'm using openxml to create Word DOCX files. I'd like to save these documents once they are created as PDF files. Is there a way I can do this in openxml? I assume the answer is no. If it is no, is there a recommended library or tool I can use to save / print DOCX files as PDF (programatically, in .NET)? I looked at sharpPDF (PDFSharp), and it seems this library is only for generating PDFs from scratch, not saving DOCX as PDF.

Can I somehow Print to an installed PDF printer, either Cute PDF or the PDF printer built in to Windows 7 in a fully automated fashion?

Update: Looking for free with non-viral license, and preferably doesn't require additional installations.

Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176

5 Answers5

11

You could do this with Word automation. You need to have word installed.

var TheDocument = TheWordApp.Documents.Open(docName);

TheDocument.ExportAsFixedFormat(
            docName.Replace(".docx", ".pdf"),
            Word.WdExportFormat.wdExportFormatPDF, 
            OptimizeFor: Word.WdExportOptimizeFor.wdExportOptimizeForOnScreen, 
            BitmapMissingFonts: true, DocStructureTags: false);

((Word._Document)TheDocument).Close();
Mo Patel
  • 2,321
  • 4
  • 22
  • 37
cellik
  • 2,116
  • 2
  • 19
  • 29
  • 2
    Microsoft Interop? Yes, this does indeed work. I was hoping to do it without having to have Word installed. This might be my path forward if there isn't a free way to do it without other dependencies. – Stealth Rabbi Aug 21 '12 at 14:24
  • 1
    @cellik:does it work with the application configured in IIS? – Saravanan Nov 23 '12 at 10:38
2

To get from DocX -> PDF you need something that can render a DocX file and provides a PDF export/save capability. Needless to say, there aren't that many tools that can render DocX (Word, OpenOffice/LibreOffice and some other licensed products mentioned below). Depending on your runtime limitations/requirements, you could try:

  1. to use MS Automation to get Word to load the docx and save as PDF.
  2. tools that sit on top of OpenOffice (JODConverter/Docmosis) to do the conversion.
  3. try embedding other document libraries (Aspose, Windward)

I'm not sure about the auto print requirement sorry.

Paul Jowett
  • 6,513
  • 2
  • 24
  • 19
1

I've successfully used the Aspose suite of tools for this in the past: https://stackoverflow.com/a/5513946/54762. It's not free, but you can demo it before you buy it.

Community
  • 1
  • 1
vinny
  • 1,810
  • 15
  • 21
0

I have used this VBScript and it works well. It works in the background (opens the docx and saves as PDF using "Save/Export as PDF" option). Check the system requirements listed on the page.

gammay
  • 5,957
  • 7
  • 32
  • 51
0

We produce WordGlue .NET which is a generic WP layout engine that can handle doc/docx.

It's completely managed and can be used to export to a variety of formats like image, XPS or (with the help of a PDF library such as ABCpdf) PDF.

I work on the ABCpdf .NET software component so my replies may feature concepts based around ABCpdf. It's just what I know. :-)