[Python Study Notes] convert wold to PDF in bulk

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.