A PDF GPS

TL;DR

Finding our way with A PDF workaround.

In latest post A PDF workaround we saw that we don’t need no stinkin’ PDF forms to merge a starting PDF with some data programmatically.

The elephant in the room, of course, is finding out where the different text parts should be placed.

Here there’s a catch. Coordinates in a PDF file must have been designed by a mathematician and not a programmer, because they have their origin in the lower-left corner and have increasing Y coordinates going up. No big deal, just a bit counterintuitive to add stuff going further down the page, and decrease the corresponding coordinate.

I was surprised by the lack of support for coordinates spotting in the tools that are widely available around, notably the Preview program in MacOS and Acrobat Reader in Windows. Well, maybe the latter is not so surprising after all.

Luckily enough, GIMP comes to the rescue (thanks to this QA in Stackoverflow). I found this procedure to be spot on:

  • start GIMP
  • open the base PDF page, setting 720 points per inch
  • flip the image vertically

At this point, the resulting image should have a good resolution and the cursor will indicate the (typical) coordinates values multiplied by 10 (i.e. (2000, 1875) in GIMP coordinates actually means (200.0, 187.5) in PDF coordinates).

It’s also possible to open the file with 72 points per inch, of course, but in my example PDF files this led to a blocky image with a lot of uncertainty about the correct positioning of my reference elements.

Stay coordinated!


Comments? Octodon, , GitHub, Reddit, or drop me a line!