doc2pdf.py 525 B

12345678910111213141516171819202122
  1. import os
  2. from pathlib import Path
  3. from win32com.client import Dispatch
  4. wdFormatPDF = 17
  5. def doc2pdf(doc_file):
  6. in_file = str(Path(doc_file).absolute())
  7. out_file = in_file[:-4] + '.pdf'
  8. word = Dispatch('Word.Application')
  9. doc = word.Documents.Open(in_file)
  10. doc.SaveAs(out_file, FileFormat=wdFormatPDF)
  11. doc.Close()
  12. word.Quit()
  13. if __name__ == '__main__':
  14. doc2pdf(os.path.dirname(__file__) + '/data/RE6404Siebrecht.doc')
  15. # add_watermark_to_folder(os.path.dirname(__file__) + '/data/')