The PDF Merger: 400 Lines of Code and Three Days of My Life
Merging PDFs sounds trivial. It took me three full days, two library switches, and one complete rewrite to get right.
Day one: I thought PDF merging would be a two-hour job. Find a library, call a function, done. I was so wrong.
The first library I tried worked fine — until you gave it PDFs with embedded fonts. The output looked like someone had sneezed on a document. Letters were fine, but kerning was off, and some characters were replaced with boxes.
Day two: I switched libraries. This one handled fonts better, but it couldn't handle PDFs that had password protection — even after you removed the password. Something deep in the file format was tripping it up.
Day three was humbling. I read the actual PDF specification. Not a blog post about it. The actual spec. 700+ pages. I didn't read all of it, but I read enough to understand why this wasn't as simple as I thought.
The final solution used a combination approach — pre-process each file to normalize it, then merge. More steps, but reliable output. And I added a "keep original order" vs "custom order" drag-and-drop feature because if I was going to spend three days on this, it was going to be good.
Every time someone uses the PDF merger today, I think about those three days. I hope it saves them at least that much time over their lifetime.