How print files in Preview to pdf from command line?

Joined
Aug 3, 2010
Messages
10
Reaction score
0
Points
1
I have a number of files. I want open them by Preview and Print them to pdf. I'm wondering if there is an automatic way to do (for example, from command line). Opening each of them manually and print them is tedious.
 
Joined
May 14, 2009
Messages
2,052
Reaction score
136
Points
63
Location
Near Whitehorse, Yukon
Your Mac's Specs
2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
Hello, Welcome to M-F :)

Download Cups-PDF, this mimics a real printer so we can access it with Automator.
Install it and open Automator.
Choose workflow, then add from the Files/Folder category "Get Specified Finder Items" add all the files you want to print by drag 'n drop or by the "Add…" button. You can add multiple files at once.
Then in the Utilities category add "Print Finder Items", select the Cups printer for the "Print to" and click the run button.
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
You can use the lpr tool to print from the CLI. Open up Terminal and execute the following:
Code:
lpr /path/to/file
That will print the file from the default printer. If you want to specify a printer, execute the following to get the appropriate printer names:
Code:
lpstat -v | awk '{ print $3; }'
Find the printer in that list and then specify for lpr by doing the following:
Code:
lpr -P <printer name> /path/to/file
When inserting the printer name in this command, exclude the colon at the end.

Take a look at the man page for lpr to see some more options (man lpr).
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top