This project provides a Python
script to merge all PDF files and images in a directory into a single PDF file.
PDFs and images are centered on custom-page-sized pages (defaults to A4
) while maintaining their aspect ratio.
- Merge multiple
PDF
files into a singlePDF
- Convert and add images (
BMP
,GIF
,JPEG
,JPG
,PNG
,TIF
,TIFF
,WEBP
) to the mergedPDF
- Center images on custom-page-sized pages (defaults to
A4
) while maintaining aspect ratio - Recursively process files in directories
- Python 3.6+
- Dependencies listed in
requirements.txt
-
Clone this repository:
git clone https://github.com/jromero132/pdf-merger.git cd pdf-merger pip install -r requirements.txt```
Run the script from the command line, providing the paths to the files or directories you want to merge:
python main.py /path/to/file1.pdf /path/to/image_directory /path/to/file2.jpg
The script will create a merged PDF
file named output.pdf in the current directory.
- PDF files (
*.pdf
) - Images:
BMP
,GIF
,JPEG
,JPG
,PNG
,TIF
,TIFF
,WEBP
- The script iterates through all provided paths.
- For each path:
- If it's a file, it processes the file.
- If it's a directory, it recursively processes all files in the directory.
PDF
files are directly inserted into the outputPDF
.- Images are converted to
PDF
pages:- Each image is centered on an custom-page-sized page (defaults to
A4
). - The aspect ratio of the image is maintained.
- Each image is centered on an custom-page-sized page (defaults to
- All processed pages are combined into a single output
PDF
file.
If you encounter any problems or have any questions, please open an issue in the GitHub repository.
Contributions are welcome! Please feel free to submit a pull request.
This project is licensed under the terms of the license file included in this repository.