Skip to content

Instantly share code, notes, and snippets.

@Tantalus13A98B5F
Created January 6, 2020 04:23
Show Gist options
  • Save Tantalus13A98B5F/fe26ed4fe0248024c3b7082d9353e7ed to your computer and use it in GitHub Desktop.
Save Tantalus13A98B5F/fe26ed4fe0248024c3b7082d9353e7ed to your computer and use it in GitHub Desktop.
A Python script to convert MSOffice files to PDF. Requires `pywin32` and MSOffice installation.
import win32com.client
msoTrue, msoFalse = -1, 0
def word2pdf(src, dst):
wdExportFormatPDF = 17
app = win32com.client.DispatchEx('Word.Application')
doc = app.Documents.Open(src)
doc.ExportAsFixedFormat(dst, wdExportFormatPDF)
doc.Close()
app.Quit()
def ppt2pdf(src, dst):
ppSaveAsPDF = 32
app = win32com.client.DispatchEx('PowerPoint.Application')
ppt = app.Presentations.Open(src, msoTrue, msoFalse, msoFalse)
ppt.SaveAs(dst, ppSaveAsPDF)
ppt.Close()
app.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment