Printing Using Python

kyosohma at gmail.com kyosohma at gmail.com
Mon Apr 16 16:40:11 EDT 2007


On Apr 16, 2:13 pm, "Raja" <rokkamr... at gmail.com> wrote:
> Hi,
>   Attached is the code . I want my program to save the current printer
> job properties and , when I reconnect the printer at a latter date , i
> need to print the saved job . Can you please help with my code ? How
> to print a document at a later stage and any errors in my code ?
>
> import win32ui
> import win32con
>
> myprinter_name = ""
> # get the name from your Printers folder
>
> printer_properties=[]
>
> def save():
>          pHandle = win32print.OpenPrinter(myprinter_name)
>          properties = win32print.GetPrinter(pHandle, 2)
>          pDevModeObj = properties["pDevMode"]
>          printer_properties.append(pDevModeObj.FormName)
>          printer_properties.append(pDevModeObj.PaperSize)
>          printer_properties.append(pDevModeObj.Orientation)
>          printer_properties.append(pDevModeObj.Color)
>          printer_properties.append(pDevModeObj.Copies)
>          printer_properties.append(pDevModeObj.DefaultSource)
>          win32print.ClosePrinter(pHandle)
>
> def apply():
>         hprinter = win32print.OpenPrinter(myprinter_name)
>
>         devmode = win32print.GetPrinter(hprinter, 2)["pDevMode"]
>         devmode.FormName=printer_properties[0]
>         devmode.PaperSize=printer_properties[1]
>         devmode.Orientation=printer_properties[2]
>         devmode.Color=printer_properties[3]
>         devmode.Copies=printer_properties[4]
>         devmode.DefaultSource=printer_properties[5]
>
>         hdc = win32gui.CreateDC("WinPrint",myprinter_name,devmode)
>         dc = win32ui.CreateDCFromHandle(hdc)
>
>         dc.StartDoc('My Python Document')
>         dc.StartPage()
>         dc.EndPage()
>         dc.EndDoc()
>         del dc
>
> You help is greatly appreciated.
>
> Thank You,
> Raja.

This sounds like a job for the pickle: http://docs.python.org/lib/module-pickle.html

I would try "pickling" the printer_properties list and when you later
need the pickled printer properties, unpickle them.

Mike




More information about the Python-list mailing list