Skip to content

Instantly share code, notes, and snippets.

@pradishb
Last active October 2, 2023 11:10
Show Gist options
  • Save pradishb/f197c503487cef929a3edb70e8a4b83e to your computer and use it in GitHub Desktop.
Save pradishb/f197c503487cef929a3edb70e8a4b83e to your computer and use it in GitHub Desktop.
Convert all xlsx files in folder to pdf using libre office in threads
import os
import concurrent.futures
from tqdm import tqdm
from glob import glob
def process_file(file_path):
os.system(f'"C:\Program Files\LibreOffice\program\swriter.exe" --headless --convert-to pdf {file_path}')
def process_files_with_threads():
files = list(glob('*.xlsx'))
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
with tqdm(total=len(files)) as pbar:
futures = [executor.submit(process_file, file_path) for file_path in files]
for future in concurrent.futures.as_completed(futures):
pbar.update(1)
process_files_with_threads()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment