Created
May 25, 2022 20:45
-
-
Save Magnus167/f320fe52938c9fc6b8aa75f44e70dbd1 to your computer and use it in GitHub Desktop.
python script to convert images to pdfs
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
| 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