How to send PDF data to a printer programmatically?

331 Views Asked by At

In MacOS, I'm using python to write PDF Service Workflows, and after processing the incoming PDF (manipulating it with PyObjC Quartz APIs), I want to send it back to the print queue and get it printed without any user effort.

Is it possible to send a Graphics Context or PDFKit data directly to the printer?

2

There are 2 best solutions below

1
On BEST ANSWER

You can use the Core Printing APIs. You can use PMPrinterPrintWithProvider() for the all-in-one approach, or the functions under Print Loop Functions to drive the print loop manually.

I don't know off-hand if those functions are available via the PyObjC bridge.

0
On

If you're using python via the command line, this sounds like a job for the Line Printer Remote lpr command line tool.

As in lpr filename.pdf or lpr -P printername filename.pdf.