Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from pathlib import Path
- from docx2pdf import convert
- # The location where the files are located
- input_path = r'c:\Folder7\input'
- # The location where we will write the PDF files
- output_path = r'c:\Folder7\output'
- # Create the output directory if it doesn't exist
- os.makedirs(output_path, exist_ok=True)
- # Check if the input directory exists
- directory_path = Path(input_path)
- if not directory_path.exists() or not directory_path.is_dir():
- print(directory_path, "is invalid")
- sys.exit(1)
- # Convert each .docx file to .pdf
- for file_path in directory_path.glob("*.docx"):
- print("Converting file:", file_path)
- output_file_path = os.path.join(output_path, file_path.stem + ".pdf")
- convert(file_path, output_file_path)
- print("Converted file:", file_path, "to", output_file_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement