I have a shell script that takes a PDF file as an argument and prints it with additional printer specific options. How can I add this script as a virtual printer that can be selected from the GUI?

The shell script is a manual duplex script that takes a PDF file, prints even pages, gives a user prompt using zenity asking the user to flip the pages and then prints the odd pages.

My current workflow is:

  1. File -> Print -> Save to file -> tmp.pdf
  2. my_duplex_script tmp.pdf
  3. rm tmp.pdf

Is there any way to make it as :

  1. File -> Print -> my_script_as_virtual_printer

Note: This is on Linux mint 13 cinnamon. I have tried gnome-manual-duplex but it doesn't work for me.

The GUI dialog from which I can print to a PDF file Standard GTK print dialog



while getopts o: opt
    case "$opt" in
        o)  lp_args="$lp_args -o $OPTARG" ;;
        \?) echo >&2 Invalid argument; exit 1 ;;
shift `expr $OPTIND - 1`

page_count=$(pdfinfo "$file" | grep Pages | awk '{print $2}')
is_odd=`expr $page_count % 2`

if [ $is_odd -eq 1 ]
    #outputting blank
    echo | lp -s -t "$file"-blank

#printing even reversed
lp -s -o page-set=even -o outputorder=reverse $lp_args -t "$file"-even "$file"

if zenity --question --text="Flip and reinsert the entire stack when printing has finished." --ok-label="Proceed" --cancel-label="Cancel"
    #printing odd reversed
    lp -s -o page-set=odd -o outputorder=reverse $lp_args -t "$file"-odd "$file"
    echo >&2 User abort
    exit 1

exit 0

I've never tried this but there is a tool called tea4cups which sounds like you could implement a prehook to your script which would do the printing. You could then have this print cancel out and not actually go to a real printer via cups, allowing your script to do the printing instead.


The possibilities are endless :

  • Send the same job to several printers at the same time, which is not possible with CUPS.
  • Automate the PDF archiving of all print jobs.
  • Forbid duplicate print jobs (a simple example is shown in the sample configuration file)
  • Create a print accounting solution in 15 minutes ( YES, THIS IS FOR REAL )
  • etc...

Tea4cups provides the following facilitates:

Tea4CUPS provides three ways to launch commands :

  • filters : A filter can modify the input datas before they are sent to the printer or made available to the pre and post hooks defined below. Currently a single filter can be defined per print queue.
  • prehooks : these are guaranteed to be launched before the print job is sent to the real printer. Any prehook which exits -1 can cancel the print job. Any number of prehooks can be defined for a particular print queue.
  • posthooks : these are guaranteed to be launched after the print job has been sent to the real printer, unless the job was previously cancelled by a prehook. Any number of posthooks can be defined for a particular print queue.

How can I add this script as a virtual printer that can be selected from the GUI?

To ad a virtual printer, just edit your /etc/printcap. This is not very easy, because the syntax of PRINTCAP need getting used to.

An example how to do it is showed here PDF Service with Samba:

# /etc/printcap
# PDF Service entry

lp|pdf|PDF Printer:\

Here the /usr/bin/smbprint script is used as a print filter. The printer itself is /dev/null.

Perhaps you'll need to install cups-bsd, but its often the default config.

  • Note that printcap is the configuration file for BSD lpr or lprNG, not for CUPS which is the de facto standard nowadays, and is the standard on Mint. – Gilles 'SO- stop being evil' Jun 14 '14 at 23:20
  • Therefore I mentioned the cups-bsd package, which is also available on Mint, by default installed and also well supported. cups-bsd is not lprng! It is only a wrapper, that provides the functionality of BSD printing for Cups in order to support applications which use lpr for printing (i.e. xpdf). – user55518 Jun 15 '14 at 12:56

Late to the party, but I wanted to do the same thing and I did not find any other solution.

I'll write here how i solved it , maybe others will find the solution useful.

  • made a filter for cups to catch the file to be printed
  • made a backend to print the file
  • made a nice and easy installer.

source code is on github: https://github.com/dentys03/manual_duplex_linux

It should work on any HP printer. Easily adapted for other printers, i guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.