To set up a print queue that will send the print job to a file, carry out the following operations as root.
Restart the CUPS service.
service cups restart
Use a command akin to the one below to create a new print queue.
lpadmin -p <queue-name> -m <generic-printer-model> -v file:/<path/to/output/file> -E
If you want to modify the settings of an existing print queue, skip the -m option and supply the name of the queue as <queue-name>.
lpadmin -p <existing-queue-name> -v file:/<path/to/output/file>
- -p <queue-name> is the name of the print queue you want to create.
- -p <existing-queue-name> is the name of the print queue you want to modify.
- -m <generic-printer-model>(optional) specifies a generic printer model type that specifies the type of file you would like to create.
- -v file:/<path/to/output/file> is the path to the output file that you would like to be created when a file is "printed."
The ability of CUPS to write data to a file is primarily intended for troubleshooting and diagnostic uses. It is not a complete feature designed for use in commercial production environments.
Avoid manually creating the output file (i.e., "path/to/output/file>"); CUPS will do so when a task is printed. If SELinux is enabled on the system, manually creating the file will result in an error saying "permission refused."
When the print queue is created, the output file is given. No CUPS technique exists to modify it such that it is distinct for every print job.
Each new print job added to the queue will overwrite the output file. There is no way for CUPS to add to an output file that already exists.
The output file will by default be produced with root-only permissions like these. # ll /tmp/output-file.txt -rw-------. 1 root root 711 May 1 14:09 /tmp/output-file.txt
However, if the file is deleted, it will be rebuilt with the root-only rights displayed above. You can change these permissions using the chmod command.
The files that CUPS creates in /tmp in CentOS 7 (and subsequent versions) aren't kept there. These files are kept in a systemd-created private temporary directory.
If you would like to have the file saved in a particular format, specify one of the generic printer models on the lpadmin command line. You can use the lpinfo command to find the generic printer models.
If you wanted to create a print queue that created a PCL file, you could use a command like.
lpadmin -p pcl-queue -m drv:///sample.drv/generpcl.ppd -v file:/var/spool/printers/pcl-queue.prn -E
lpadmin -p pdf-queue -m lsb/usr/cupsfilters/Generic-PDF_Printer-PDF.ppd -v file:/var/spool/printers/pdf-queue.pdf -E