Ctrl + M: Merging PDFs Like a Boss With Python PDF Merger GUI

Day 19 of 100 Days Coding Challenge: Python

Have you ever stood at your flatbed scanner, flipping page after page like a 90s office clerk in a movie montage, only to realize—“Oh great, now I have five separate PDFs that should have been one”? Welcome to my world. We’ve got one of those dinosaurs of a scanner that spits out a new file for every single page, and while it’s good at being stubborn, it’s not great at convenience. Sure, there are free websites that claim they’ll merge your files in a flash.

But when those PDFs contain personal, sensitive, or just plain embarrassing content (say, your creative attempts at calligraphy), uploading them to a mystery website isn’t exactly comforting. So I did what any slightly paranoid, slightly annoyed person would do—I made my own PDF merger. Because sometimes, security means building your own tools with a splash of Python and a sprinkle of stubbornness.

Today’s Motivation / Challenge


Today was about practicality. Merging PDFs sounds boring until you actually need to do it—and then you realize it’s oddly satisfying, like organizing your bookshelf by color or alphabetizing your spice rack. Also, there’s something empowering about replacing a clunky online tool with your own sleek script. This challenge hit that sweet spot between “annoyed enough to act” and “curious enough to build.”

Purpose of the Code (Object)


This little Python program takes all the PDF files in a folder and smooshes—yes, smooshes—them together into one tidy document. No need to click through a bunch of file pickers. No typing long file paths. Just point it to a folder, and poof! One big, shiny PDF.

AI Prompt:


“Rewrite the script so that it automatically merges all .pdf files in a folder, no typing required. Also, make it a GUI version.”

Functions & Features

  • Select a folder via a simple GUI window
  • Automatically find and merge all .pdf files in that folder
  • Save the merged file with a custom filename

Requirements / Setup


To run the program, you need:

bash

CopyEdit

pip install PyPDF2

Python 3.x is recommended (Tkinter is usually pre-installed)

Minimal Code Sample

from tkinter import filedialog

import os, PyPDF2

folder = filedialog.askdirectory()

pdfs = sorted([f for f in os.listdir(folder) if f.endswith(“.pdf”)])

merger = PyPDF2.PdfMerger()

for pdf in pdfs:

    merger.append(os.path.join(folder, pdf))

merger.write(“merged_output.pdf”)

This merges all PDFs in the selected folder in alphabetical order.

PDF Merger

Notes / Lessons Learned


This was my first Python GUI script that I actually plan to use often—and honestly, that’s the best kind. My first version worked, but it asked me to type full file paths like some kind of unpaid intern. One typo, and it all crashed. Then I remembered that I am, in fact, very lazy. So I upgraded to a GUI. One click to select the folder. No paths, no quotes, no drama. It’s exactly the kind of script that “future me” will thank “past me” for—like finding frozen soup in the back of the freezer when you’re starving. Am I proud? Absolutely. Will I use this over and over? Also yes.

Optional Ideas for Expansion

  • Add drag-and-drop support for merging selected files
  • Let the user reorder files before merging
  • Show a preview of filenames and file sizes before final merge

Leave a Reply

Your email address will not be published. Required fields are marked *