Skip to content

Instantly share code, notes, and snippets.

@saosir
Created September 5, 2019 13:22
Show Gist options
  • Select an option

  • Save saosir/e4b963e28b39043c9c4ea212eeb958e8 to your computer and use it in GitHub Desktop.

Select an option

Save saosir/e4b963e28b39043c9c4ea212eeb958e8 to your computer and use it in GitHub Desktop.
windows下 word 转 pdf
# -*- coding:utf-8 -*-
import os
import comtypes
from comtypes.client import CreateObject
wdFormatPDF = 17
in_file = os.path.abspath('f:/xx.docx')
out_file = os.path.abspath('f:/xueweizheng.pdf')
word = CreateObject('Word.Application')
doc = word.Documents.Open(in_file)
doc.SaveAs(out_file, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment