Printing Using Python

R

Raja

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.
 
K

kyosohma

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
 
R

Roger Upole

Raja said:
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.

You should be able to pause the job using win32print.SetJob
with JOB_CONTROL_PAUSE and resume it later using
JOB_CONTROL_RESUME. That way you won't even have
to store the print parameters yourself.

hth
Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top