16

I have PDF file in which I want to trim all the white space around as much as possible. It has to automatically detect and do it.

I use Foxit reader and it has option to crop pages automatically while viewing.

But I am looking for a command line solution in Linux.

I tried PDFCrop but it crops all the pages uniformly. I want it to crop based on the white space around each individual page using this command:

pdfcrop input.pdf output.pdf

But it works only partially, some pages are cropped but some are not.

Giacomo1968
  • 55,001
Santhosh
  • 689

1 Answers1

22

The best way to remove margins is using pdfCropMargins

Install:

pip install pdfCropMargins --upgrade

Now we can use the command pdf-crop-margins to crop the pdf the way we want

I want to crop all the pages and then add 6bp margin all around. I can do that by

pdf-crop-margins -v -p 0 -a -6 input.pdf

-v : Verbose -p : how much percentage of margin to be retained. We want the bounding box triming all the white margins on all sides. So say 0% -a : Note: first -p is applied to create a bounding box. IN this option it applies further on the bounding box after -p is applied. we can remove or add margin. Negative means add margin to the bounding box. So it will add 10bp all around after cliping

The output file is affixed with _cropped

Also I checked the cropped file and all the contents and links are intact.

Greenonline
  • 2,305
  • 11
  • 25
  • 32
Santhosh
  • 689