Possible Duplicate:
Which free software can I use to deskew scanned images

I have several PDFs made up of book pages' scans. The scans are made from two pages at a time and some of these scans are skewed, making text appear slightly tilted.

I'm looking for a tool that could allow me to do an automatic optimization by deskewing the scans without losing readability. I've found the GPL software Briss to crop the scans in order to have a 1:1 page ratio instead of 2:1, but I don't have any tool to deskew the pages.

I stumbled upon unpaper, another open source tool that seems perfect for what I want to do, but that tool is Linux only and it doesn't work on PDF files directly.

Any hint is appreciated.

  • 1
    @random: Why has this question been closed?? Why should this topic solicit 'debate, arguments, polling or extended discussion'?!? Jul 8, 2012 at 0:40
  • 1
    "looking for a tool" is pretty much polling for services leads to the not constructive close reason @kur
    – random
    Jul 8, 2012 at 0:43
  • 1
    @random: This question led me to do some research about the topic, and I found some interesting options to persue. The most interesting one is using ImageMagick for this, and it seems surprisingly simple. Unfortunately your closing of this does not allow me to post my answer. Jul 8, 2012 at 0:58
  • @random: I'v now edited the question a bit. Hopefully it is now more compliant to your sense of 'constructiveness'. Jul 8, 2012 at 1:50
  • @random: Ok, 'closing as duplicate' is better acceptable to me in this case. Jul 8, 2012 at 10:00

2 Answers 2


Have a look at deskew. It's a commandline tool. The download *zip seems to include binaries for Windows, MacOSX and Linux.

License is MPL (Mozilla) or LPGL (GNU), whatever you prefer.

The only drawback for you seems to be that it doesn't consume PDFs, only PNG and TIFF images (AFAICS). That means you'll have to set up a workflow of s.th. like:

 PDF.orig -> PNG.orig -> PNG.deskewed -> PDF.deskewed

I haven't tested it myself (yet), I just came across the website recently and bookmarked it.

  • deskew did manage to correct rotation-related distortion in my test run but unfortunately it introduced a thin gray line at the position of the original image border. To get rid of the gray border I cropped the images with the -extent option of mogrify. I only tested on OS X, maybe this misbehaviour is platform-specific. May 25, 2015 at 19:45
  • deskew works really well. My workflow is like this: pdfimages -all <pdf> my_imagesjbig2 -s -p -v my_images* > outputpdf.py output > deskewed.pdf If black borders (result of deskewing operation) bothers you, some processing with imagemagick might be necessary, like suggested by @StefanSchmidt
    – Mr. Tao
    Aug 9, 2018 at 15:16

Oh, let me add another answer. I just remembered netpbm. Haven't used it in years, but I think I should take a fresh look...

netpbm is a very powerful toolkit for the commandline to manipulate of graphic images. It ships nearly 300 separate tools. It includes converters for about 100 graphics formats.

And it also has a commandline tool that can rotate images:


And it has another tool that tries to discover the angle of rotated images:


pamtilt returns a floating number of its guess of image rotation. So the automatic de-skewing of images should be within reach. A shell script could be written to do that. It would require different steps:

  1. Convert PDF page to an netpbm-suitable image format with the help of Ghostscript.
  2. Use pamtilt to auto-discover the skew angle of the image.
  3. Use pnmrotate to de-skew the image.
  4. Re-convert the image to PDF.

If you provide me access to a small sample of your PDF files I could try and come up with a shell script to accomplish the feat.

(I'm wondering heavily that [netpbm] doesn't seent to have a tag here on the superuser+stackoverflow.)

Not the answer you're looking for? Browse other questions tagged or ask your own question.