First method, you can use the command line tool “ImageMagick“.
1 2 3 4 5
# Before running, make sure you image files are named in order, # such as "001.jpg", "002.jpg", "003.jpg" and so on. magick *.jpg comic.pdf # OR: magick *.png comic.pdf
The second method, you can use Python script with the “Pillow“ library support.
defconvert(image_folder: str, target_pdf: str) -> None: # Get list of image files. image_files = sorted( [f for f in os.listdir(image_folder) if f.lower().endswith(('.jpg', '.png'))] ) images = [] for file in image_files: img_path = os.path.join(image_folder, file) img = Image.open(img_path).convert('RGB') images.append(img) # Save all images to a single PDF. if images: images[0].save(target_pdf, save_all=True, append_images=images[1:])
The easiest way seems to use the command line tool “pdfimages” provided by “poppler“.
1 2 3 4 5 6 7 8 9 10 11 12 13
# Install "poppler" on macOS: brew install poppler # Or on Debian/Ubuntu: sudo apt install poppler-utils # Run the following commands to extract images from PDF file. # The "prefix" value below will be used to name the extracted # image file. With the command above, you will get image files # with name like: # prefix-000.jpg # prefix-001.jpg # prefix-002.jpg # ... pdfimages -all comic.pdf prefix
The questions I sent to ChatGPT were:
How to convert a batch of comic image files in “jpg/png” formats into a single PDF file?