How to print PDF files automatically from a directory?

6,956
  1. Install the package inoticoming

    sudo apt-get install inoticoming
    
  2. Install the package trash-cli to use your trash folder instead of deleting the PDF

    sudo apt-get install trash-cli
    

    If you prefer the deletion of the file via the classical rm, than you don't need this package and you have to replace the line

    lpr "$2/$1" && trash "$2/$1"
    

    with

    lpr "$2/$1" && rm "$2/$1"
    

    in the script below.

  3. Create wrapper script printpdf

    mkdir -p ~/bin
    gedit ~/bin/printpdf
    
  4. Add the code below, save the file and close the editor

    #!/usr/bin/env bash
    FILE="$1"
    if [ "${FILE##*.}" = "pdf" ]
    then
        lpr "$2/$1" && trash "$2/$1"
    fi
    exit 0
    
  5. Make the script executable

    chmod +x ~/bin/printpdf
    
  6. Watch your folder

    inoticoming /path/to/MY-SHARED ~/bin/printpdf {} /path/to/MY-SHARED \;
    

And as @Rmano said in the comments

About point 4, notice that is practically impossible to be sure that the file has been printed. You can check it has been sent to the printer, but printed is quite more complex and really never fail-proof (and probably printer-dependent).

Share:
6,956

Related videos on Youtube

maryuri sanzonetti
Author by

maryuri sanzonetti

Updated on September 18, 2022

Comments

  • maryuri sanzonetti
    maryuri sanzonetti almost 2 years

    Currently, I have a directory called MY-SHARED, and I need the following to happen:

    1. Print all PDF files that I place into MY-SHARED
    2. The printing must initiate automatically (no human interaction)
    3. After printing, it should automatically delete the file

    How can I accomplish such task?

    As a side note, I'm novice in the Ubuntu world.

    • Rmano
      Rmano almost 9 years
      About point 4, notice that is practically impossible to be sure that the file has been printed. You can check it has been sent to the printer, but printed is quite more complex and really never fail-proof (and probably printer-dependent).
  • Rmano
    Rmano almost 9 years
    +1, even if you forgot to delete the file after printing (or at least moving in a trash, on the line of lpr [...] && mv file trash) ;-)
  • A.B.
    A.B. almost 9 years
    @Rmano Ups o_O =)
  • maryuri sanzonetti
    maryuri sanzonetti almost 9 years
    Great guys, now all my home computers can print to the Epson L200 printer installed on the station with Zorin 9.1. At home my dad has a notebook with Linux Canaima. And now I need not install drivers. Also happens to my mom using a Chromebook like mine, it's just print the PDF to said network folder and everything working. Thanks very much, I love you a world ;-*
  • maryuri sanzonetti
    maryuri sanzonetti almost 9 years
    If I have a problem I call to 0800 ASKUBUNTU GUYS! hehehe