The code of this article is rewritten by the original ppt2pdf.py
"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "", "" "". "" "" "" "" "" "" "" "," "" "" "," "" "" "," "" "," "" ">> Word2pdf.py>> Author: Liu Yang>> e-mail: [email protected]>> blog: Www.cnblogs.com/liu66blog "" " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "". "" "" "" "" "" "" "" "" "" "" "" "" "" #!/usr/bin/env python#-*. " -Coding:utf-8-*-import sys, os# call COM component Package Import comtypes.clientdef Init_word (): Word = Comtypes.client.CreateObject (" Word.Application ") word. Visible = 1 return word# Second step: Locate all doc (x) files under the path and add their paths to cwddef Convert_files_in_folder (Word, folder): # Add all current files and folders File = Os.listdir (folder) # print (' Files: ', files) # Add all Files ending in. doc (x) to CWD path pptfiles = [F for f in Fil Es if F.endswith ((". Doc", ". docx")])] for pptfile in PPTFiles: # added to determine if the currently converted PDF already exists, skip adding print (Pptfile) If Pptfile+ '. pdf ' in Files:break # join CWD Environment FullPath = Os.path.join (CWD, Pptfile) Ppt_to_pdf (Word, FullPath, FullPath) #第三步: Convert CWD path to PDF format def ppt_to_pdf (Word, inputfilename, outputfilename, formattype = 17): # Slicing suffix is pdf i F outputfilename[-3:]! = ' pdf ': outputfilename = OutputFileName + ". pdf" # call interface to convert print (inputfilename) d Eck = Word. Documents.Open (InputFileName) deck. SaveAs (OutputFileName, formattype) # formattype = + for Word to PDF deck. Close () if __name__ = = "__main__": # Create Word app Word = Init_word () # get current path CWD = OS.GETCWD () # Print current path prin T (CWD) # call Word to convert the doc (x) format under CWD path Convert_files_in_folder (Word, CWD) # After the conversion is complete, close word. Quit ()
[Python Study Notes] convert wold to PDF in bulk