I know this question has been asked before, but there was no clear answer.
How do I change the printer tray programmatically?
I am trying to use python to batch print some PDFs. I need to print different pages from different trays. The printer is a Ricoh 2232C. Is there a way to do it through and Acrobat Reader command line parameter? I am able to use the Win32 api to find out which bins correspond to which binnames, but that is about it. Any advice/shortcuts/etc?
Ok, I figured this out. The answer is:
1. you need a local printer (if you need to print to a network printer, download the drivers and add it as a local printer)
2. use win32print to get and set default printer
3. also using win32print, use the following code:
import win32print
PRINTER_DEFAULTS = {"DesiredAccess":win32print.PRINTER_ALL_ACCESS}
pHandle = win32print.OpenPrinter('RICOH-LOCAL', PRINTER_DEFAULTS)
properties = win32print.GetPrinter(pHandle, 2) #get the properties
pDevModeObj = properties["pDevMode"] #get the devmode
automaticTray = 7
tray_one = 1
tray_two = 3
tray_three = 2
printer_tray = []
pDevModeObj.DefaultSource = tray_three #set the tray
properties["pDevMode"]=pDevModeObj #write the devmode back to properties
win32print.SetPrinter(pHandle,2,properties,0) #save the properties to the printer
printing is accomplished using internet explorer (from Graham King's blog)
from win32com import client
import time
ie = client.Dispatch("InternetExplorer.Application")
def printPDFDocument(filename):
ie.Navigate(filename)
if ie.Busy:
time.sleep(1)
ie.Document.printAll()
ie.Quit()
Done
That's not possible using plain PDF, as you have create new print job for any particular bin and tray combination (and not all printers allow you to do that, Xerox 4x and DP Series allows you to do such things).
My best bet would be juggling with PostScript: convert PDF to PostScript, where you have access to individual pages, then extract the pages you need and for each such page (or pages) create new print job (eg. using Windows program lpr
). To ease the task, I'd create print queue for any combination of bin and tray you have to print to, then use these queues as printers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With