While preparing for a concert yesterday, I needed to copy a bunch of scores (in PDF format) over to a pad. They were all from different sources, and some had been scanned upside down. They looked fine on my computer, so I couldn’t understand why they ended up being shown upside down on my pad.
After some investigation, I realized that it was because the rotation was written into the metadata of the file. This worked fine on my laptop but not in the score reader program on my pad. If you want a file to be truly rotated by 180 degrees, you should rotate and then flatten that rotation so the orientation is baked into the PDF.
qpdf to the rescue
CoPilot suggested that I use qpdf, a command-line tool and C++ library that performs content-preserving transformations on PDF files. Then, all that is needed is to run something like this:
qpdf --rotate=+180:1-z --flatten-rotation input.pdf output-rotated.pdf
where:
--rotate=+180:1-zrotates all pages (1-z) by 180 degrees.--flatten-rotationrewrites the file so the rotation is applied to page content.
Verify the result
You can inspect page rotation metadata with the tool pdfinfo:
pdfinfo output-rotated.pdf | grep -i rotate
Depending on the toolchain, a truly flattened file may show Rotate: 0 (because rotation has been baked in) while still looking correctly rotated.
