This project provides Python scripts for converting images to PDFs, extracting images from PDFs and merging PDFs. It includes multiple methods using different libraries to achieve high-quality conversions.
- Convert images (
.png
,.jpg
, etc.) to a PDF. - Extract images from a PDF and save them as separate image files.
- Merge two or more PDFs.
- Different implementations using PIL (Pillow), img2pdf, PyMuPDF (Fitz) and PyPDF2.
- Supports high-quality output and maintains page order.
Install the required Python packages:
pip install pillow img2pdf pymupdf PyPDF2
You can use any of the following methods:
Run the following command:
python img_to_pdf1.py
- Drawback: Only works if the folder contains only images (otherwise throws error).
Run the following command:
python img_to_pdf2.py
- Pros: Maintains high image quality with DPI support.
Run the following command:
python img_to_pdf3.py
- Pros: Handles different image sizes and maintains full resolution.
Run the following command:
python pdf_to_img.py
- Output: Saves extracted images in the
pdf_images
folder.
Run the following command:
python mergePdf.py
- Output: Combines/merges PDFs present in the current directory.
- Ensure the images are named properly (e.g.,
page_1.png
,page_2.png
, etc.) to maintain order. - If running into sorting issues, manually check the filenames before conversion.
- If image quality is low, use img2pdf or PyMuPDF for better results.