PDF Conversion Issues

How to Batch Merge Images into PDFs Preserving Folder Structure

John WilsonJohn Wilson Nov 2, 2026 869 views

Question details

The user needs to convert collections of images stored across multiple subfolders into individual PDF files (one PDF per folder) without altering the existing directory structure.

Batch Merge Images into PDFs While Preserving Folder Structure
Product
Adobe Acrobat / Python
Device & OS
not provided
Scenario
Organizing scanned documents or photo archives that are separated into categorized folders, requiring an automated way to generate a single PDF for each category.
Observed behavior
Requires a batch processing solution or API method to automate the conversion, as doing it manually folder-by-folder is too time-consuming.
Before you start

Ensure all your images are properly sorted and named in their respective folders, and make a backup copy of your main directory before running any batch processing scripts.

Solution 1Recommended

Automate Conversion Using a Python Script

Python is the most flexible and efficient method to recursively process folders and generate a specific PDF for each directory using libraries like img2pdf.

By leveraging Python's built-in os module alongside image processing libraries like Pillow or img2pdf, you can easily iterate through all subdirectories, gather the image files, and output a combined PDF perfectly aligned with your folder structure.

1
Install required Python libraries

Open your terminal or command prompt and run the command 'pip install img2pdf' to install the necessary PDF conversion library.

2
Set up the folder traversal script

Create a new Python file and use 'os.walk()' to loop through your root directory, identifying all subfolders.

3
Collect images per folder

Within the loop, create a list of files that end with image extensions (like .jpg or .png) located inside the current subfolder.

4
Convert and save the PDF

Pass the list of image file paths to 'img2pdf.convert()' and write the binary output to a new PDF file named after the folder, saving it in the desired output directory.

Automate Conversion Using a Python Script
High Efficiency: This Python method can process thousands of images across hundreds of folders in seconds without manual intervention.
Efficient PDF Processing Tools

Easily Convert Images to PDF with WPS Office

While complex folder automation requires coding, WPS Office provides an incredibly user-friendly Image to PDF tool for quick, high-quality document creation. It perfectly preserves image quality, allows easy reordering, and is an excellent alternative for manual or smaller-scale batch conversions.

  1. 1. Launch WPS Office: Open the WPS Office application on your computer and navigate to the 'PDF' tab.
  2. 2. Select Picture to PDF: Click on the 'Picture to PDF' option located in the top tool ribbon.
  3. 3. Import Your Images: Click 'Add Pictures' and select all the images from your desired folder that you wish to combine.
  4. 4. Merge and Convert: Ensure the 'Merge in one PDF' option is checked, then click 'Convert' to generate and save your final PDF document.
Merge multiple images into a single PDF with just a few clicksHighly compatible with Adobe PDF and Microsoft Office formatsLightweight application that runs smoothly on any systemEasily adjust page sizes, margins, and image orientations
microsoft office alternative - wps office

Frequently Asked Questions

Can I batch merge images to PDF without writing code?

Yes, there are specialized batch-processing utilities and third-party software available that offer folder-aware merging features without coding. However, for precise control over subfolder structures, a simple Python script remains the most reliable free method.

What is the best image format for PDF conversion?

JPEG is highly recommended for photographs to keep the final PDF file size manageable. PNG is better for text-heavy images, screenshots, or graphics where lossless quality is required.

Will the output PDF preserve my original image dimensions?

When using command-line tools like img2pdf, the exact pixel dimensions are preserved by default. If you use GUI software like WPS Office, you typically have the choice to either fit the image to standard page sizes (like A4) or maintain the original image dimensions.