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.
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.
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.)
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.
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.
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();
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:
I'm not sure about the auto print requirement sorry.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With