tags:

views:

973

answers:

3

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?

+1  A: 

There is no easy way to do this, since you indicate you want to choose specific pages from the pdf and print them to specific bins using Acrobat Reader

Example: Print page 1 on letterhead bin 1, page 2 on stock bin 2

Acrobat Reader only allows printing of the whole document from the command line:

You could alter the freeware Ghostscript and do what you want.

or this commercial product should do the job. PDFPrint


See the Acrobat Reader developer FAQ on page 24 for more details

AcroRd32.exe /t path "printername" "drivername" "portname" — Start Adobe Reader and print a file while suppressing the Print dialog box. The path must be fully specified.

The four parameters of the /t option evaluate to path, printername, drivername, and portname (all strings).

printername — The name of your printer.

drivername — Your printer driver’s name, as it appears in your printer’s properties.

portname — The printer’s port. portname cannot contain — Your printer driver’s name, as it appears in your printer’s properties.

portname — The printer’s port. portname cannot contain

Noah
+1  A: 

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.

zgoda
+2  A: 

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
  1. that's it, the tray has been changed
  2. 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

jle