1

I'm cropping and rasterizing some PDFs using ImageMagick. In order to remove some text that I don't need, I want to crop to a smaller box than needed and then readjusting the page size adding some white space.

To rasterize and crop, i proceed as follows:

for filename in *.eps; do
    convert -density 150 -crop "$bbwpx"x"$bbhpx"+"$xoffpx"+"$yoffpx" \
      +repage "$filename" "${filename%.*}.png"
    convert "${filename%.*}.png" "${filename%.*}.pdf"
done

Following this answer, I then want to increase the height of the page. Therefore I added one more line to the code shown above to get:

for filename in *.eps; do
    convert -density 150 -crop "$bbwpx"x"$bbhpx"+"$xoffpx"+"$yoffpx" \
       +repage "$filename" "${filename%.*}.png"
    convert "${filename%.*}.png" "${filename%.*}.pdf"
    gs -q -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile="${filename%.*}-crop.pdf"\
      -dDEVICEWIDTHPOINTS="$bbw" -dDEVICEHEIGHTPOINTS="$bbhnew" -dFIXEDMEDIA -c \
      "<< /CurrPageNum 1 def /Install {0 $bbcorr translate} bind  >> \
      setpagedevice" -f "${filename%.*}.pdf"
done

However, after running this, the height always remains the same as before (as shown by pdfinfo), the content of the pdf is however correctly translated.

Running the code on not rasterized PDFs works, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.