Created
May 4, 2025 12:26
-
-
Save mvark/68f2b4b9b699286cc016f6247687c1ed to your computer and use it in GitHub Desktop.
ChatGPT generated Python script to merge PDFs using the GNU GPL v3 licensed PDF-handling library PyMuPDF. Install it using the command before running the script - pip install pymupdf
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 fitz # PyMuPDF is also known as fitz | |
# List of PDFs to merge | |
pdf_files = ['file1.pdf', 'file2.pdf', 'file3.pdf'] | |
# Create a new empty PDF | |
output_pdf = fitz.open() | |
# Loop through each file and insert pages | |
for file in pdf_files: | |
with fitz.open(file) as pdf: | |
output_pdf.insert_pdf(pdf) | |
# Save the merged result | |
output_pdf.save("merged_pymupdf.pdf") | |
output_pdf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment