File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import os
2+ from docx2pdf import convert
3+
4+ def convert_word_to_pdf (word_file_path ):
5+ try :
6+ output_pdf_path = os .path .splitext (word_file_path )[0 ] + ".pdf"
7+ convert (word_file_path , output_pdf_path )
8+ print ("Conversion successful. PDF saved" )
9+ except Exception as e :
10+ print (f"Error occurred during conversion: { e } " )
11+
12+ if __name__ == "__main__" :
13+ # Replace the paths below with the actual paths of your Word files
14+ word_files = [
15+ r"enter word file location path 1" ,
16+ r"enter word file location path 2" ,
17+ r"enter word file location path 3" ,
18+ r"enter word file location path 4" ,
19+ r"enter word file location path 5" ,
20+ r"enter word file location path 6" ,
21+ r"enter word file location path 7" ,
22+ r"enter word file location path 8" ,
23+ r"enter word file location path 9" ,
24+ # you can add as many as you want
25+ ]
26+
27+ for word_file_path in word_files :
28+ convert_word_to_pdf (word_file_path )
You can’t perform that action at this time.
0 commit comments