Skip to content

Instantly share code, notes, and snippets.

@mvark
Created May 4, 2025 12:26
Show Gist options
  • Save mvark/68f2b4b9b699286cc016f6247687c1ed to your computer and use it in GitHub Desktop.
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
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