Question

What I need to be able to do is to rotate a PDF clockwise or counter clockwise either programmatically or from the CLI.

I have spent considerable time researching and attempting to rotate PDFs with GhostScript (as GS is already installed for other reasons) to no avail, nothing seems result in any rotation.

I have looked into using pdftk but it requires java libraries, and I would rather not have java installed on the system.

We've even looked at modifying the PDF file ourselves, and we have had some success with this, but we haven't come across a reliable method that works for all PDFs.

So my #1 preference would be to achieve this with existing resources on the system. My #2 preference would be to do a little modification to the existing system as possible to achieve this.

The server in question is using Linux (OpenSuse 11) with PHP 5.2 and I have Ghostscript 9.0 installed.

Any advice would be much appreciated.

Was it helpful?

Solution

You can use pdfpages LaTeX package

\documentclass{article}
\usepackage{pdfpages}

\begin{document}
    \includepdf[angle=45]{document.pdf}
\end{document}

The LaTeX document above, compiled via pdflatex, produces a document rotated 45 degrees.

There are also tools (wrappers of pdfpages) like pdfjam that can be used directly from command line:

$ pdfjam --suffix rotated45 --angle 45 --fitpaper true document.pdf

OTHER TIPS

There is a way to do this with ImageMagick, if that's available to you.

Example:

$ convert originalfile.pdf -rotate <cw_angle_degrees> newfile.pdf

Note, however, that since this is a raster-based rotation, there will (generally) be a noticeable loss of quality AND increase in filesize.

You haven't said how you are trying to do this with Ghostscript, but if you want to use the pdfwrite device you will need to set /AutoRotatePages=/None or it will rotate the final page so that the majorty of any real text is horizontal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top