Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Usually, I'm pretty happy using pdfcrop, even though the cropped output usually consumes significantly more disk space. Note that comparable code does exist, which addresses and resolves this issue. However, if wanting to crop a scanned (image) pdf file, my impression is that pdfcrop simply fails. I imagine that ImageMagick is capable of doing the trick, possibly by (also) making us of pdftk.

I'm looking for an efficient one-liner of code (a multi-line script would also be ok...) to crop such a pdf file from Top-Bottom-Left-and-Right by x cm each (or, better yet, by a b c d cm, individually), going all the way from input.pdf to output.pdf.

ps: the solution needn't involve ImageMagick; I'm happy as long as it works (cleanly, reliably and efficiently)... ;)

share|improve this question
a genius just answered this question programmatically here –  nutty about natty Mar 27 '13 at 16:26

3 Answers 3

You could try briss. It's pretty simple, but does the job. It's a GUI app though.

Download the zip file and extract to a folder of your choice and start it:

java -jar briss-0.9.jar

To install it permanently and system-wide and be able to start it from anywhere with just briss, you would unpack the download in /usr/local/lib/, then create an executable file /usr/local/bin/briss that contains:

java -jar /usr/local/lib/briss-0.9/briss-0.9.jar
share|improve this answer

This here is the best and easiest and has a wonderful GUI: Krop

Download deb from the author:


Working on 13.10 like a charm.

share|improve this answer
up vote 2 down vote accepted

Full credit is due to AlexG who incidentally en passant posted a solution to this problem here, which, for completeness sake and so it doesn't get lost (!), I quote below.

Relevant to the above question is the trimming option described in the man:

Usage examples:

#default operation orig.pdf cropped.pdf -m 10 orig.pdf cropped.pdf -hires orig.pdf cropped.pdf

#trimming pages -t "10 20 30 40" orig.pdf trimmed.pdf

Content of


function usage () {
  echo "Usage: `basename $0` [Options] <input.pdf> [<output.pdf>]"
  echo " * Removes white margins from each page in the file. (Default operation)"
  echo " * Trims page edges by given amounts. (Alternative operation)"
  echo "If only <input.pdf> is given, it is overwritten with the cropped output."
  echo "Options:"
  echo " -m \"<left> [<top> [<right> <bottom>]]\""
  echo "    adds extra margins in default operation mode. Unit is bp. A single number"
  echo "    is used for all margins, two numbers \"<left> <top>\" are applied to the"
  echo "    right and bottom margins alike."
  echo " -t \"<left> [<top> [<right> <bottom>]]\""
  echo "    trims outer page edges by the given amounts. Unit is bp. A single number"
  echo "    is used for all trims, two numbers \"<left> <top>\" are applied to the"
  echo "    right and bottom trims alike."
  echo " -hires"
  echo "    %%HiResBoundingBox is used in default operation mode."
  echo " -help"
  echo "    prints this message."

mar=(0 0 0 0); tri=(0 0 0 0)

while getopts m:t:h: opt
  case $opt
    eval mar=($OPTARG)
    [[ -z "${mar[1]}" ]] && mar[1]=${mar[0]}
    [[ -z "${mar[2]}" || -z "${mar[3]}" ]] && mar[2]=${mar[0]} && mar[3]=${mar[1]}
    eval tri=($OPTARG)
    [[ -z "${tri[1]}" ]] && tri[1]=${tri[0]}
    [[ -z "${tri[2]}" || -z "${tri[3]}" ]] && tri[2]=${tri[0]} && tri[3]=${tri[1]}
    if [[ "$OPTARG" == "ires" ]]
      usage 1>&2; exit 0
    usage 1>&2; exit 1
shift $((OPTIND-1))

[[ -z "$1" ]] && echo "`basename $0`: missing filename" 1>&2 && usage 1>&2 && exit 1
[[ -n "$1" ]] && output=$1 && shift;

    [[ "$c" -eq 0 ]] && gs -dNOPAUSE -q -dBATCH -sDEVICE=bbox "$input" 2>&1 | grep "%%$bbtype"
    pdftk "$input" output - uncompress
) | perl -w -n -s -e '
  BEGIN {@m=split /\s+/, $mar; @t=split /\s+/, $tri;}
  if (/BoundingBox:\s+([\d\.\s]+\d)/) { push @bbox, $1; next;}
  elsif (/\/MediaBox\s+\[([\d\.\s]+\d)\]/) { @mb=split /\s+/, $1; next; }
  elsif (/pdftk_PageNum\s+(\d+)/) {
      print "/MediaBox [", join(" ", @mb), "]\n";
    } else {
      @bb=split /\s+/, $bbox[$p];
      print "/MediaBox [", join(" ", @bb), "]\n";
' -- -mar="${mar[*]}" -tri="${tri[*]}" -c=$c | pdftk - output "$output" compress
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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