12

I'm writing a piece of software that supports multiple printers. In order to test it, I need to add multiple printers to my CUPS server. How can I do that?

I want to add a few fake printers that will send the jobs directly to /dev/null. That way, I can watch the "completed jobs" list in CUPS interface and observe if my software is using the correct printer for each job.

migrated from stackoverflow.com Jun 30 '11 at 20:11

This question came from our site for professional and enthusiast programmers.

11

One solution is to install cups-pdf. It adds a virtual printer that writes PDF files. There are several tutorials on the web about how to install and configure it; since I use Gentoo, I've read Gentoo-wiki, which also mentions Sabayon wiki.

cups-pdf virtual printer has a configuration file in /etc/cups/cups-pdf.conf, and by default all PDF files are written to /var/spool/cups-pdf/${USER}.

(NB: On Ubuntu it writes to ~/PDF/)

There are a few limitations, though:

  • Since there is only one configuration file, multiple PDF printers will save to the same directory.

  • It is impossible to print "raw" data (using, for instance, lpr -o raw). Even sending a PDF file as a raw job will not work. Raw print jobs will generate a blank PDF file with just an empty page.

Even with these limitations, it works perfectly for my needs.


Footnote: if the user is using Gnome, or printing through a GTK+ application, then there is already a "Print to File" pseudo-printer at the print dialog. Thus, why should the user still want to add a virtual PDF printer? Here are a few reasons:

  • That "Print to File" is specific to GTK+, and is not available for non-GTK+ applications. (maybe KDE has a similar feature, but I'm not sure)
  • It makes possible to generate a PDF from Flash "applications" that were designed for printing. For instance, the PocketMod.
  • Adding a virtual printer to CUPS makes it possible to test printing using shell scripts or other software that talks directly with CUPS. This is specially useful for developers while testing their applications.
  • It is possible to "share" this virtual printer with the local network. Not exactly useful, but possible.
  • It is possible to attach a post-processing command to be executed right after the PDF file has been saved.
9

The Cups Forum has a more complete/accurate answer to this question.

The answer is that the device URI should be set to file:/dev/null

So in my Ubuntu setup:

  • Device URI: file:/dev/null
  • Make and Model: Local Raw Printer

Which works for me perfectly.

I searched the Cups forum again and found this:

Commandline Null Printer Setup in Cups Forum

In your cupsd.conf:

FileDevice yes

Setup Printer

lpadmin -p nowhere -E -v file:/dev/null

Testing Printer

who |lp -d nowhere
  • I am just looking at my printout now: fine details, vibrant colours it plain jumps off the page at me. ... hey waitaminute .... – Andrew Russell Mar 13 '12 at 22:42
  • Thank you. I needed a dummy printer in my Virtual Machine to screenshot some instructions. :) – njallam Aug 24 '12 at 18:58
7

You can create a printer that outputs to /dev/null with lpadmin:

$ sudo lpadmin -p myprinter -E -v file:///dev/null

This will be written to /etc/cups/printers.conf, but you can also view printers with lpstat:

$ sudo lpstat -s
myprinter accepting requests since Thu 22 Jan 2015 11:04:46 AM GMT
system default destination: myprinter
device for myprinter: ///dev/null

Note that you may need to enable FileDevice in /etc/cups/cupsd.conf on old Linux distros.

To make your new printer the default, use lpoptions:

$ sudo lpoptions -d myprinter
  • How to remove it? – Richard Sep 5 '15 at 19:01
  • @Richard Use lpadmin -x myprinter or the web interface. – Torkel Bjørnson-Langen Jan 5 '17 at 23:06
2

One of the best solution is to use ippserver. It comes with CUPSv2.2.2 and higher. You can alternatively get the project from here: IPP sample implementations.

According to the description on the manual page:

ippserver is a simple Internet Printing Protocol (IPP) server conforming to the IPP Everywhere and IPP Shared Infrastructure Extensions (INFRA) specifications. It can be used as a standalone print server and/or a very basic infrastructure server between standard IPP clients and IPP proxies conforming to the INFRA specification.

To use it, all you need to do is run ippserver "My cool printer", and it will create a virtual printer with the name My cool printer for you. It runs like a web server and listens on specific ports.

In case you need multiple printers, you can run the server on multiple ports using ippserver "My other cool printer" -p 8888.

You can even supply printer attributes using an attributes file. For instance, your printer supports by default high quality prints, you can add the following attribute in the attributes file:

ATTR enum print-quality-default high

and run the server using:

ippserver "My high quality cool printer" -a attributes-file.txt

References:

  1. PWG IPP Sample
  2. CUPS ipptoolfile man page
1

Taken from http://inai.de/linux/adm_virtualprinter:

Virtual printer in CUPS

To create a printer in CUPS that sends the data nowhere (like /dev/null), there are many ways. This page uses the socket:// method.

Set up xinetd first

What we need is the TCP Discard service on port 9. Xinetd has it built-in, so we can just use that. Make sure that the following definition is available in xinetd's configuration file(s), usually /etc/xinetd.d/discard. It should contain a service like the following:

    service discard
        type            = INTERNAL
        id              = discard-stream
        socket_type     = stream
        protocol        = tcp
        user            = root
        wait            = no
        disable         = no
        FLAGS           = IPv6 IPv4 
Run rcxinetd reload to reread the configuration files and activate the new discard service. Or use rcxinetd start if xinetd was not already active.

CUPS printer

Now go to the CUPS web frontend and add a new printer. As destination, use socket://localhost:9/, as printer choose something that looks featureful, for example the "HP 2500C Foomatic/pcl3". That's all there is to it.

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.