leandropoblet
9 years agoFrequent Contributor
Need to save an .rtf file as .pdf using MS Word. Which version would you recommend?
Hi there,
I tried recording scripts on MS Word 2010 64 and 32 bits and non of them work.
I also tried Office 365 although I knew it wouldn't.
Any suggestions?
I only need to open a file, save it as PDF and that's it.
Thanks in advance,
Leo
Hi Leandro,
All Microsoft Office products provide an API in the form of COM objects that let you automate all kinds of things, including saving files to a different format. Word's COM object is Word.Application. You can use the Application.Documents.Open(FileName) method to open a file and the Document.SaveAs(FileName, FileFormat) method to save it to a specific format. Here's an example:
// JScript function Test() { RTF2PDF("C:\\Work\\Example.rtf", "C:\\Work\\Example.pdf"); } function RTF2PDF(RTFFileName, PDFFileName) { var wdFormatPDF = 17; var oWord = Sys.OleObject("Word.Application"); var oDoc = oWord.Documents.Open(RTFFileName); oDoc.SaveAs(PDFFileName, wdFormatPDF); oDoc.Close(); oWord.Quit(); }
This works for me in Word 2010.
Helpful links: