Print pdf file directly without opening it?
Solution 1
Use lpr to print PDF files directly from the command-line
I don't think you can do that directly, no. However, there's a command line program called lpr
which sends pdf files directly to the printer. So if you have doc.pdf
, you should be able to print it with lpr doc.pdf
(assuming you're in the right folder on the command line).
You can also view the printer queue with lpq
- besides the queue, this shows which is the default printer, and what its status is...
See the other answer for how to add lpr to the right-click menu.
Solution 2
Add lpr to the right-click menu
I didn't know about 'lpr' that Steve mentioned about, but I know how to add it to your right click menu, using the Nautilus Scripts function of Nautilus.
Just copy and paste the below text to Gedit:
#!/bin/bash
IFS_BAK=$IFS
IFS="
"
for line in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
if [[ "$line" = "" || "$line" = " " ]]; then
exit
fi
lpr "$line"
sleep 1;
done
IFS=$IFS_BAK
IFS_BAK=
Save the file as 'Send to Printer' and then, right click on it->Properties->Permissions->Tick "Allow executing file as program"
Finally, move the file under ~/.gnome2/nautilus-scripts
Now, in every .pdf file you want, you can right click on it and choose Scripts->'Send to Printer'. The command 'lpr' that Steve mentioned about will execute to the file you have selected.
Related videos on Youtube
HeyPaul
Updated on September 18, 2022Comments
-
HeyPaul almost 2 years
Currently I open the file in document viewer and select print etc. Is it not possible to right click the file and "send to" the printer?
-
Mitch almost 12 yearsWhat Ubuntu release are you using?
-
-
HeyPaul almost 12 yearsAaaargh - it doesn't work from windows shares! I print orders from a win98 program to pdf files. Then in ubuntu I print to paper.
-
hytromo almost 12 yearsHm, that sounds logical, you should have mentioned that you wanted to work through windows shares, though :/ I don't know how nautilus scripts work through windows shares.... I will test it and post back. EDIT: I cannot currently test it but you could first download the pdfs from the network to your hard disk and then use the script...
-
HeyPaul almost 12 yearsYes - but then I might as well just open them directly and print them!!
-
hytromo almost 12 yearsNo, it is not the same. The failure is logical: The files are not in your PC, you can only see their filenames, how can your PC send them for printing? You can download all of them, select all of them and choose right-click->'Send to Printer'
-
robertspierre over 5 yearsThanks. Is there a way to avoid that lp and lpr prints PDF annotations (like highlights)?
-
Ossi Viljakainen over 5 yearsI receive regularly bunch of pdf's packed into a single zip file. I would like to right-click to send all the pdf's contained in the zipfile directly to printer by lpr. How should I modify the script to enable unzip | lpr?
-
hytromo over 5 years@OssiViljakainen If you right click on a zip file, you can execute the script the same way.
$line
will be your zip file. Now, look atmktemp -d
to create a temp dir, then useunzip
to extract the file inside the temp dir, then usefind
in the temp dir to find all the pdf files and executelpr
on them. Then remove the temp folder. That's the simplest thing I can think of