Knowledge Base
Searching in : Article
ID: AR09P00997
Applies to: NoMachine Software
Added on: 2018-09-04
Last Update: 2018-09-06

How to print from command line on Linux overriding default settings like 'fit to page'

By default, documents on Linux are printed with the 'fit to page' setting enabled, i.e. text is scaled to fit the paper size.

To avoid that text is shrinked to adapt to the page, it's possible to specify additional options in the command line used for printing. This can be done also when connected by NoMachine to the remote Linux host:

1) Connect by NoMachine to the remote computer.
 
2) Connect a local printer and make it available from the user's computer to the NoMachine session.
 
3) Inside the NoMachine session open a terminal and execute the following command to list all the printers available on server side:

lpstat -a -d

4) Print the file from command line on a specific printer. The name of printers forwarded via NoMachine has 'NoMachine' as postfix. For example:

lp -d HP_LaserJet_1018_NoMachine ~/Desktop/index.jpeg

This command prints the file with the default settings, included the 'fit to page' one.

 

To print without scaling content to the page size it's necessary to specify an additional parameter. When 'fit to page' is disabled, it's possible to specify also the percentage of the scale value:

-o fitplot=False  turn off printing in ‘fit-to-page’ mode

When 'fit to page' is disabled, it's possible to specify also how a printed image will be scaled:

-o natural-scaling=percent scale the image in relation to the natural image size

-o scaling =percent scale the image in relation to the page

For example:

lp -d HP_LaserJet_1018_NoMachine -o fitplot=False -o natural-scaling=400 ~/Desktop/index.jpeg

For more details about the available options and their usage, we recommend to refer to the official CUPS documentation at https://www.cups.org/documentation.html.

Note: in a similar way it's possible to print from command line also on Mac.

 

TIP
 

To disable 'fit to page' by default when printing from command line, it's possible to create a wrapper script which executes the lp command with the appropriate options.

a) Rename /usr/bin/lp to /usr/bin/lp.ori


b) Create the script, for example:


#!/bin/bash

if [ -e "/usr/bin/lp" ];
then
 LP_COMMAND="/usr/bin/lp.ori"
else
 echo "ERROR: lp not found."
 exit 1
fi

$LP_COMMAND "$@" -o fitplot=False


c) Move the script, named lp, to /usr/bin in order to replace the original one.

d) Ensure that the new wrapper script, lp, has the same ownership and permissions of the original one.