doc to pdf
https://stackoverflow.com/a/6018039
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| import sys import os import comtypes.client
wdFormatPDF = 17
in_file = os.path.abspath(sys.argv[1]) out_file = os.path.abspath(sys.argv[2])
word = comtypes.client.CreateObject('Word.Application') doc = word.Documents.Open(in_file) doc.SaveAs(out_file, FileFormat=wdFormatPDF) doc.Close() word.Quit()
|
using pywin32
:
1 2 3 4
| import win32com.client
word = win32com.client.Dispatch('Word.Application')
|
ppt to pdf
1 2 3 4 5 6 7 8 9 10 11
| var source=WScript.Arguments.Item(0);
var target=source.substr(0, source.lastIndexOf('.'))+".pdf"; PP = new ActiveXObject("PowerPoint.Application"); PRSNT = PP.presentations.Open(source,0,0,0)
PRSNT.SaveAs(target,32); PRSNT.Close(); PP.Quit();
|
Reference
https://docs.microsoft.com/en-us/office/vba/api/word.wdsaveformat
https://docs.microsoft.com/en-us/office/vba/api/powerpoint.ppsaveasfiletype