In OSX, I want to print to a file from the terminal.
I have two solutions, but both have drawbacks.
1. Use 'cupsfilter'
cupsfilter -m application/vnd.cups-postscript \
-p /etc/cups/ppd/my_printer.ppd \
-o Duplex=DuplexNoTumble \
-o PageSize=A4 \
-o landscape my_document.pdf \
> my_document.ps
(The .ppd file is from my default printer)
I can now send this file to the printer with the raw
option (avoiding any cupsfilters)
lp -o raw my_document.ps
But the drawback is that the printing result is not correct and not the same as when I print the normal way to my default printer.
lp -o Duplex=DuplexNoTumble -o PageSize=A4 -o landscape my_document.pdf
On some investigation, I can see that some of PJL headers are different for both methods.
-@PJL SET BINDING = SHORTEDGE
+%@PJL SET BINDING = LONGEDGE
When running the cupsfilter command with the option --list-filters
I see:
cgpdftops
pstops
It seems two filters are run. I think this is wrong, but I don't know for sure and I don't know how to change this.
2. Creating a File backend
You can do this with:
sudo lpadmin -p to_file \
-P /etc/cups/ppd/my_printer.ppd \
-E \
-v file:///tmp/my_document.ps \
-m raw
You probably get a warning and have to uncomment the following line in /private/etc/cups/cups-files.conf
and set it to yes
FileDevice Yes
and then restart cups
sudo launchctl stop org.cups.cupsd
sudo launchctl start org.cups.cupsd
You can now print to a file with the following command:
lp -d to_file \
-o Duplex=DuplexNoTumble \
-o PageSize=A4 \
-o landscape my_document.pdf
The created .ps file is owned by root, so to print it to the default printer I have to use sudo
sudo lp -o raw /tmp/my_document.ps
The problem with this solution is (besides the hassle with the file permission) that I can not define the name of the output file. I don't like to re-create the to_file
backend for every print job.
So is there any other solution that gives me a file with the exact same data that otherwise was send to the printer?