Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving Word DOCX files as PDF [closed]

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.

like image 422
Stealth Rabbi Avatar asked Aug 20 '12 20:08

Stealth Rabbi


People also ask

Why can't I save my Word doc as a PDF?

When you get this error when trying to save Word Doc as PDF, you will need to use Save As from the drop-down option before you click Save. Make sure that you choose the PDF option in the "Save As" window.

Why does my Word doc save as PDF?

What has apparently happened is that the file association for . docx files has become reassigned to Adobe Reader or whatever application you use to open and read PDFs. (I assume that if your documents still have a . docx extension and still display a Word icon and that you can open them from within Word.)

Can a DOCX file be saved as a PDF?

1Open your docx document in MS Word 2013. 2Click on the File tab and select Save as. 3Choose the folder where you want to save the file. In the drop-down menu Save as type, choose PDF.

Why is my computer saving everything as a PDF?

This might be caused due to corrupted default file association on the computer. Perform the following troubleshooting methods: Method 1: I would suggest you to set default file association and then check if this fixes the issue.


3 Answers

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();
like image 159
cellik Avatar answered Sep 21 '22 01:09

cellik


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.

like image 40
Paul Jowett Avatar answered Sep 22 '22 01:09

Paul Jowett


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.

like image 20
vinny Avatar answered Sep 20 '22 01:09

vinny