On page 78 of the PDF Specification 2008, it mentions that the PDF's page object has an integer key value Rotate that you can set to tell the software how the page should be displayed. This value shall be multiple of 90 degrees. enter image description here

So a lot of tools would simply rotate the pdf page by simply setting this key and leave the original page content untouched. I am wondering if there is a way to change orientation of the page by modifying the actual page stored in pdf directly, instead of doing this marker-style modification?

So what I am trying to achieve here is:

Rotate the page (say) 90 degrees physically instead of simply setting the Rotate key value to 90. (That's to say the value of Rotate should remain 0 after rotation.)

Any command line tools can be used here? I have tried the pdftk, but it only sets the Rotation key.

  • You can use mutool to decompress streams, edit with a text editor and modify the transformation matrix for the page using the Postscript commands, then compress and fix the xref. I wouldn't be surprised if there are command line tools that already do that for you, but in general it can be difficult depending on how the page is drawn (blindly inserting a transformation won't always work).
    – dirkt
    Oct 12, 2018 at 11:32
  • You might look at converting the pdf to PostScript (eg with pdf2ps) then using tools like pstops from psutils to rotate the page using the page matrix.
    – meuh
    Oct 13, 2018 at 15:37
  • For others coming here to achieve the rotation without modifying the page data to achieve it, you can use qpdf --rotate=270:1 original.pdf rotated.pdf (where 270 in this case is the angle in degrees and could be 90, 180 or 270 depending on the desired outcome). Oct 31, 2019 at 12:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.