9

How can I rotate a PDF file less than 90 degree under Ubuntu?

Can I do that interactively?

slm
  • 369,824
Tim
  • 101,790

4 Answers4

7

You can do that with ConTeXt.

  • does not rasterize
  • allows for individual angles for individual pages
  • allows for varying page sizes

Versions before 2013.10.07 09:47 had a bug which cropped the pages, so make sure you use a version including the fix.

First create a file (e.g. rotatepdf.tex) with the following content

\getfiguredimensions [\getdocumentargument{input}]
\starttext
  \dorecurse{\noffigurepages}
    {\startTEXpage
      \externalfigure
        [\getdocumentargument{input}]
        [page=\recurselevel,
         orientation=\getdocumentargument{rotation}]
    \stopTEXpage}
\stoptext

Then you can rotate a PDF using the following command line:

context --input=somefile.pdf --rotation=10 rotatepdf.tex

Here is an example output:

screenshot

Marco
  • 33,548
6

I looked hard and long and could find no tool that allowed you to do this interactively that is a native PDF viewer type of tool. I did not try this but you might be able to use Inkscape or Gimp to do this. I think the only issue you'll likely run into with using them is the ability to batch rotate a multi-page document.

Even the command line tools such as PdfTk couldn't do rotation by degrees, which really surprised me.

However using ImageMagick you can rotate PDF files in 1 degree increments.

Examples

$ convert original.pdf -rotate 45 rot45.pdf

You can put any value you want in for the rotate argument. It will also take negative numbers so this is possible:

$ convert original.pdf -rotate -45 rot-45.pdf

The quality of the output will drop off dramatically using the default options so you'll likely need to include the -density switch to increase the quality of the resulting PDF file.

$ convert -density 300x300 original.pdf -rotate 45 rot45.pdf

Resulting PDF

Here's a screenshot of Evince with the resulting PDF file.

   ss of pdf

slm
  • 369,824
  • 4
    Imagemagick or Gimp rotate by first rasterizing, which is often not desirable. – Gilles 'SO- stop being evil' Oct 05 '13 at 14:35
  • @Gilles - yeah I know, I've been searching for another method, but coming up empty. There is an SU Q&A that shows using programmatic methods, but that seems a bit beyond what would be appropriate here. Have you found any other methods. There was a page I came across that said Acrobat Pro can do rotates by 1 degree increments but I couldn't tell if it was doing rasterizing too or not. – slm Oct 05 '13 at 14:47
  • Thanks,slm! Can the method by convert rotate every page in a single multiple-page pdf file? @Gilles: in my case, the pdf files are created by scanning. So I think rasterizing first doesn't matter? – Tim Oct 05 '13 at 14:49
  • @Tim - yeah since they're scans they've already been rasterized. Yes it does every page. – slm Oct 05 '13 at 14:54
  • @Tim - yes, that's what the example shows, it converted a multi-page document. – slm Oct 28 '13 at 17:06
  • @slm: thanks! but it only convert the first page of one of my pdf files – Tim Oct 28 '13 at 17:07
  • @Tim - something must be up with that PDF file then. Where did it come from? The results above are exactly what I used and got. No doctoring of the screenshots was done 8-) – slm Oct 28 '13 at 17:08
  • @slm: I realized the two pages of the pdf file need to rotate different angles. How can I do that? – Tim Oct 28 '13 at 17:09
  • @Tim - that's a different question. This one was asked and answered, I'd ask that as another question. – slm Oct 28 '13 at 17:10
  • @slm: I followed the command convert -density 300x300 original.pdf -rotate 45 rot45.pdf to preserve the quality, but the size increases from 100KB to 2MB. What can I do to reduce the size without sacrificing the quality? I used a online compressing website http://compress.smallpdf.com/, but it takes forever to compress and hasn't finished yet. – Tim Oct 28 '13 at 17:31
3

This has also been asked on stackoverflow.com.

Another option is using LaTeX:

\documentclass{standalone}
\usepackage{graphicx}

\begin{document}
\includegraphics[angle=-1.5]{odd-scan}
\end{document}

In this case, I have the file odd-scan.pdf (a slightly rotated one page scan) in the same folder as the LaTeX file rotated.tex with the content above and then I run pdflatex rotated.tex. The output is a file rotated.pdf with the PDF rotated by 1.5 degrees clockwise.

Phimor
  • 31
1

You could import it with GIMP, which includes a rotate tool and can export back to pdf.