PDF is such a weird format. Not so long ago I had to write some Java code for manipulating PDFs: find a string, remove it and place an image at the former string position. I should have known better as I thought "Well, how hard can that be?”
What followed was a deep dive down the rabbit hole, a lot of fiddling with the same tools the author of this gist is using trying to make sense of it all.
The final solution worked better than I thought while at the same time felt incredibly wrong.
I'm very thankful for all the (probably painful) work that went into those open source PDF tools.