Skip to content

Instantly share code, notes, and snippets.

@Magnus167
Created May 25, 2022 20:45
Show Gist options
  • Select an option

  • Save Magnus167/f320fe52938c9fc6b8aa75f44e70dbd1 to your computer and use it in GitHub Desktop.

Select an option

Save Magnus167/f320fe52938c9fc6b8aa75f44e70dbd1 to your computer and use it in GitHub Desktop.
python script to convert images to pdfs
import img2pdf, glob, os
from tqdm import tqdm
def main():
os.makedirs(name='imgs_as_pdfs', exist_ok=True)
for img in tqdm(glob.glob('./*.png')):
with open(img, 'rb') as f:
pdf = img2pdf.convert(f)
with open(f'imgs_as_pdfs/{img[:-4]}.pdf', 'wb') as f:
f.write(pdf)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment