MATLAB: How to save a Word document as a PDF via ACTXSERVER in MATLAB 8.2 (R2013b)

MATLAB

I am trying to save a Word document as a PDF using the ACTXSERVER function in MATLAB together with the Word method PRINTOUT. Although I am specifying that the output file name should have a PDF extension, I do not see it being created.

Best Answer

The following reference to the Window.PrintOut method in the Word 2013 Dev Center:
<http://msdn.microsoft.com/en-us/library/office/ff197226.aspx>
shows the syntax of this method to be:
expression.PrintOut(Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight)
(Please note that depending on the Word version the number of parameters can vary.)
However, the method PRINTOUT only allows you to print the document to a printer. If you want to save your Word document as a PDF document, you can use the method SAVEAS2. For example:
wrd = actxserver('word.application');
wrdDoc = wrd.Documents;
wrdFile = wrdDoc.Open('TestWord.docx');
wrdFile.SaveAs2('TestWord.pdf',17);
wrdDoc.Close;
wrd.Quit();
where 17 stands for the PDF format.
For more information about formatting values, you may wish to refer to the following link:
<http://msdn.microsoft.com/en-us/library/office/bb238158(v=office.12).aspx>
and the following link provides further information about SAVEAS2:
<http://msdn.microsoft.com/en-us/library/ff836084.aspx>