Automate printing with options?
I am trying to print a file (a pdf), without intervention. Not Automator specific, I can deal with applescript or terminal or whatever. The specifics of what I want are:
- Print to specific Printer
- Print to specific Page Size (Non-Standard)
- Auto-Rotated (Optional)
- Scale to Fit, Print Entire Page (Ends up being 109 to 112%. 110% works)
I can do this manually through Preview's print menu, only the page size is non-default, but I want to automate it, drag and drop, somehow.
Things I tried:
- If I print from Finder, it uses Preview, but it's blown out of size, and wrong Page size.
- If I drag it onto the printer in ~/Library/Printers/printername, it's like using LP, but without the options.
- Applescript's printing options are poorly documented.
- Automator's "Print Finder Items" it's like #1.
- Automator's "Print Images" is like Preview but "Scale to Fit" does not work like Preview does, I can't choose the page size, and "Auto-Rotate" doesn't work at all.
- If I print from terminal via LP or LPR, I can set page size and orientation/fit-to-page, but I can't scale it to 110%. This is the closest thing to what I want.
How can I do this? It shouldn't be so hard, I want to do what the GUI can, not like I want extra features.
Worst case, how can I emulate mouse or keyboard control of Preview's print menu? All that would be needed is to 1. open file, 2. Bring up print menu, 3. switch to a preset or page size, as all the other options including scaling are default., 4. press print/enter.
Solution 1:
Let's split the problem into two parts: scaling and printing.
Scaling
You can scale a PDF on the command line. Consider creating a temporary, scaled, PDF to print.
See scaling PDF content and page dimensions from command line for suggested approaches to this. The highest voted answer suggests using cpdf with a command like:
cpdf -scale-page "1.1 1.1" in.pdf -o out.pdf
An alternative tool is sips
. This tool is included with OS X and is surprisingly capable.
Printing
As you have discovered, OS X's printing system is the Common Unix Printing System (CUPS). CUPS includes the command line tool lpr
which can accept all the settings and options you need.
For printing the PDF via the command line see:
- Print PDF from Command Line – cups-pdf, lpr -P PDF
- CUPS printing of pdf files
To list the available printers, use:
lpstat -p -d
To print a PDF file to the default printer, use:
lpr file.pdf