How to print a PDF from the command line and scale it on Linux

Written by James McDonald

September 25, 2021

What I want to do:

Print an A6 PDF centred on an A4 page from the command line on Linux

What I tried:

Tried to use evince and Firefox but they have no command line print options for linux.

What worked:

Calculate the margins and run lp or lpr by doing the following

Dimensions of A4 are 210mmx297mm

Dimensions of A6 are 105mmx148mm

So to print an A6 page centred in an A4 the margins in mm

Calculating the short side margins

210mm-105mm = 105mm

105/2 = 52 .5mm

Calculating the long side margins

297-148=149mm

149/2 = 74.5mm

There are 72 points (pt) per inch an inch is 25.4mm so divide the margin size in mm by 25.4 to get the size in inches and then multiply by 72 to get the size in points.

Convert millimetres to points

Short side

In points (52.5mm/25.4mm) * 72 = 149pt

Long side

In points (74.5mm/25.4mm) * 72 = 211

So the margin-left and right value is 149pt and the margin-top & bottom value is 211pt

The lp or lpr commands are as follows

Note that this sends to the default printer you may need to specify a printer too. (run man lp or man lpr to get the options)

lp -n 1 -o page-ranges=1 -o fitplot=true -o page-bottom=211 -o page-top=211 -o page-left=149 -o page-right=149 barcode99.pdf
lpr -#1 -o page-ranges=1 -o page-ranges=1 -o fitplot=true -o page-bottom=211 -o page-top=211 -o page-left=149 -o page-right=149 barcode99.pdf

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...

Ubuntu on Hyper-v

It boils town to installing linux-azure # as root or sudo apt-get update apt-get install linux-azure...