How to send to print (many) selected files in a directory instead of one by one?

11,766

Solution 1

I have done a script that will send the desired files to the default printer: you may have to modify it to select the folder that your files are in and run it once for .pdf and then for .txt:
find /home/mike/KeyGuides/ -type f -iname '*.txt' -print0 | while IFS= read -r -d '' f; do lpr "$f"; done. It does work as I have just tested it; just make sure the desired printer is set up as default.

If you have any problems, I'll see if I can modify it as necessary. (You can use other options for lpr if you need -see man lpr) It should work for most printers- it is successful with my Canon IP4700.

This version of the script also moves each printed document to a directory (which you must have created previously), so that when the script is run only new documents are printed:

find /home/mike/Duck/ -type f -iname '*.txt' -print0 | while IFS= read -r -d '' f;
 do lpr "$f" && mv "$f" /home/mike/Duck/printed/ ; done

Solution 2

Create the file: ~/.local/share/applications/print.desktop Put in:

[Desktop Entry]
Encoding=UTF-8
Name=Print Directly
Comment=Print file directly with default printer.
Exec=lp %f
Type=Application
Icon=/usr/share/pixmaps/gnome-applets.png
MimeType=text/plain;text/pdf;application/pdf;application/x-pdf

Right click on any pdf file, in the "Open with..." view the extended list of available application for pdf files. Find the "Print Directly" entry and add the association. From now on you can right click on any pdf file (or groups) and have them printed with the lp command on your default printer. If you want to make experiments, install the CUPS-PDF printer and set it as default in the Printers settings.

sudo apt-get install cups-pdf

You will have test file "printed" into ~/PDF folder.

Solution 3

The solution to this is very simple. Go to the desired folder and, in a terminal do:

for FILE in *.pdf ; do lpr "$FILE" ; done

This is from https://ubuntuforums.org/showthread.php?t=921960

Share:
11,766

Related videos on Youtube

Oscar
Author by

Oscar

Updated on September 18, 2022

Comments

  • Oscar
    Oscar almost 2 years

    I'm using Ubuntu 12.04 and succesfully installed my wi-fi printer, but my question is: How to print many files at a time? I mean, I have many PDF or text files in a folder and I want to send them directly to printer instead of opening one by one in file viewer and then to print and then repeat the whole process so many times /:

    I even see no Print option when right clicking on the file or in the File menu.

    Thank you!

  • Oscar
    Oscar almost 12 years
    Hi, I added the action and command in Nautilus as indicated, the menu appears when right clicking the file but nothing happens /: The terminal method did work, but when printing pdf files, the resulting printed page have other fonts and not the ones you see when opening with the visor.
  • Oscar
    Oscar almost 12 years
    Hi: thanks for your advice, but what if I want to print many files but no all the files on that dir? That's what I'd like to do, because as I new files get saved on that dir I only print the new files. Hope I explained it well :)
  • FEarBG
    FEarBG almost 12 years
    That's really a different question to the original one asked, but I'll see if I can do something with the script- it might be tricky to just print the ones not already printed; although what we could do is just add a command to move each document to a specified folder after it has been printed. It should be possible to insert that into the while loop.
  • FEarBG
    FEarBG almost 12 years
    Please note that lpr only works on plain text. You will have to use another tool that sends a print job to CUPS if this is about PDFs, for instance.
  • Oscar
    Oscar almost 12 years
    Hi, not so different question, that's why I put "many" and "selected" in the question's name, so that can be all of them or some of them :D OK, hope you find a solution to achieve it. Many thanks!
  • FEarBG
    FEarBG almost 12 years
    lpr does work with pdfs- the command lpr bash_FAQ.pdf does print it out perfectly.
  • Oscar
    Oscar almost 12 years
    @Cumulus007 the lpr command did work, I could send all my pdf files directly to my HP printer without problem, the only issue was that fonts were not printed as the documents looked on screen.
  • FEarBG
    FEarBG almost 12 years
    @Oscar if you look at the edited version of my answer, a new version of the script now sends each printed document to a folder (which you create beforehand), so that you don't have to print them all out again each time. I think I have solved the original question!
  • FEarBG
    FEarBG almost 12 years
    In that case you are lucky for the fact that your printer can convert PDF files to Postscript on its own, or it actually can interpret PDF files.
  • David M. Sousa
    David M. Sousa almost 12 years
    Sorry, but this is not my own knowledge. I gnawed at some sites to grab the information I just posted. You should check, on the Nautilus case, the lp's documentation. Maybe it isn't targeting your printer.
  • Javier Rivera
    Javier Rivera almost 12 years
    @Cumulus007: No. I have a system in production (around 10 users), that mainly creates pdfs and send then to lpr for printing to different printers. Most of them low cost HPs than can only understand PCL.
  • Javier Rivera
    Javier Rivera almost 12 years
    CUPS expects postscript (plain text and PDFs are a subscript), gives it to the drivers to transform to the printer language, and then send it to the printer. So it will work with PDFs, but no with odt.
  • jonathan
    jonathan over 3 years
    PPA no longer working in 20.04