Created
December 17, 2023 21:53
-
-
Save 0187773933/3bc611e9b855a32e6f1c54a4d3fe005f to your computer and use it in GitHub Desktop.
libreoffice convert docx to pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import sys | |
import subprocess | |
def docx_to_pdf( docx_folder ): | |
docx_files = [f for f in os.listdir(docx_folder) if f.endswith('.docx')] | |
total_files = len(docx_files) | |
for i, docx_file in enumerate(docx_files, 1): | |
docx_path = os.path.join(docx_folder, docx_file) | |
print(f"Converting file {i} of {total_files}: {docx_file}") | |
# subprocess.run(['libreoffice', '--headless', '--convert-to', 'pdf', docx_path, '--outdir', docx_folder]) | |
subprocess.run(['/Applications/LibreOffice.app/Contents/MacOS/soffice', '--headless', '--convert-to', 'pdf', docx_path, '--outdir', docx_folder]) | |
if __name__ == "__main__": | |
docx_to_pdf( sys.argv[ 1 ] ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment