4

The problem is that my printer always cuts off some part on the borders of my PDF files. Normally this isn't a problem because most PDFs already have a bit of space at the border. But now I have a few documents which I need to print that don't have such space.

Is there a linux command line tool (or batch processing tool) to resize the content of each page to for example 95% of its original size while preserving the page dimensions?

Edit: I need more space on all four sides.

2 Answers 2

3

Check out this blog post from 2008 showing how you can do this with ghostscript, and this shell script pdfScale that wraps it up nicely for you.

The blog gives this example for a 90% scale on A4 paper:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER \
  -dCompatibilityLevel="1.3" -dPDFSETTINGS="/printer" \
  -dSubsetFonts=true -dEmbedAllFonts=true \
  -sPAPERSIZE=a4 -sOutputFile="out.pdf" \
  -c "<</BeginPage{0.9 0.9 scale 29.75 42.1 translate}>> setpagedevice" \
  -f in.pdf

and the script reduces this to

pdfScale -s 0.9 in.pdf out.pdf

as well as automatically detecting the media page size. Other heavyweight tools include pdfjam and pdfedit.


The pdfScale script has been much enhanced since this answer was written in Feb 2017. See the link above for all the options.

4
  • Both don't work for me: $ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dSAFER -dCompatibilityLevel="1.3" -dPDFSETTINGS="/printer" -dSubsetFonts=true -dEmbedAllFonts=true -sPAPERSIZE=a4 -sOutputFile="out.pdf" -c "<</BeginPage{0.9 0.9 scale 29.75 42.1 translate}>> setpagedevice" -f infile.pdf gives me GPL Ghostscript 9.10: Set UseCIEColor for UseDeviceIndependentColor to work properly. Unrecoverable error: stackunderflow in .setdistillerparams. The other one is here: github.com/tavinus/pdfScale/issues/1
    – Max Matti
    Commented Feb 7, 2017 at 19:35
  • There is another version of the gs command where -dPDFSETTINGS="/printer" is replaced by -dPDFSETTINGS="/screen" which should work. For pdfScale, make sure grep /MediaBox in your file only produces a single line beginning /MediaBox.
    – meuh
    Commented Feb 8, 2017 at 9:18
  • Hi. I am not sure about the problems with pdfscale, but I would look into it if you open an issue there. Took me almost 2 years to even find this here. Also, I have rebuilt the grep method of detection a year ago or so and also included many other fine tuning parameters for the ghostscript call, so you can change more stuff on the GS call without needing to hack anything. You can change /printer to /screen for example. I am also making extra checks on parsed data so it fails better if needed. The 2-line replacement above should be totally obsolete and not recommended, btw.
    – Gus Neves
    Commented Sep 27, 2018 at 5:47
  • @GusNeves Thanks for the info and the changes to pdfScale. I've removed some obsolete stuff from my answer.
    – meuh
    Commented Sep 27, 2018 at 7:32
0

use "cpdf" command line tool to scale the contents of the pdf

cpdf INPUT.PDF -scale-contents "0.9" -o OUTPUT.PDF

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .