I've been working on a weekly record. Because the weekly work records are mostly separate word files, sometimes forget it is not easy to find out, one by one to open the search too hard, so think of these files through the word2016 of the Save as function into PDF, and then Yong Acrobat merged together.
Ideas are as follows:
(1) Search through the Python code for all Word documents in the specified input directory, call the Word COM interface, and dump the file into a PDF file to the specified output directory;
(2) Use Acrobat to merge all the PDFs in the output directory into a single PDF file for archival review.
The code for Step (1) is as follows:
1 ImportOS2 #Import Comtypes.client3 Importwin32com.client4 Import Time5 6 7Wdformatpdf = 178 9 #absolute path is neededTen #Be careful about the slash ' \ ', use ' \ \ ' or '/' or raw string R ' ... " OneIn_dir=u'Input Directory' AOut_dir=u'Output Directory' - -Word = Win32com.client.Dispatch ('Word.Application') theWord. Visible =True -Time.sleep (3) -first_flag=True - + Try: - forRoot, dirs, filesinchOs.walk (in_dir): + forFileinchFiles: A if(File.endswith (". docx")orFile.endswith (". doc")) and( notFile.startswith ('~')): atin_file=os.path.join (root, file) -out_file_temp=Os.path.join (out_dir,file) -Out_file=out_file_temp.rsplit ('.', 1) [0]+u'. pdf' - #print (in_file) - #print (out_file) - #Skip existed files in ifOs.path.isfile (out_file): - Continue to Print "================================================" + Print "convert\n '"+in_file+"' into\n"+ Out_file +"' \ n" -Doc=Word. Documents.Open (In_file) theDoc. SaveAs (Out_file, fileformat=wdformatpdf) * Doc. Close () $ ifFirst_flag:Panax NotoginsengWord. Visible =False -First_flag =False the exceptException as Inst: + Print(Type (inst))#The exception instance A Print(Inst.args)#arguments stored in. Args the Print(Inst)#__str__ allows args to be printed directly, + - Word. Quit () $ Print "coversion done."
Step (2):
You can see the name of each file becomes a bookmark for easy reference.
Reference:
Http://stackoverflow.com/questions/6011115/doc-to-pdf-using-python
Convert Word documents to PDF files in bulk