Skip to content

Instantly share code, notes, and snippets.

@0187773933
Created December 17, 2023 21:53
Show Gist options
  • Save 0187773933/3bc611e9b855a32e6f1c54a4d3fe005f to your computer and use it in GitHub Desktop.
Save 0187773933/3bc611e9b855a32e6f1c54a4d3fe005f to your computer and use it in GitHub Desktop.
libreoffice convert docx to pdf
#!/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