A module encapsulating the Windows printing API.
-
Retrieves a handle to a printer.
-
Retrieves information about a printer
-
Changes printer configuration and status
-
Closes a handle to a printer.
-
Connects to a network printer.
-
Disconnects from a network printer.
-
Enumerates printers, print servers, domains and print providers.
-
Returns the default printer.
-
Returns the default printer.
-
Sets the default printer.
-
Sets the default printer.
-
Notifies the print spooler that a document is to be spooled for printing. Returns the Jobid of the started job.
-
The EndDocPrinter function ends a print job for the specified printer.
-
Deletes spool file for printer
-
Notifies the print spooler that a page is to be printed on specified printer
-
Ends a page in a print job
-
Starts spooling a print job on a printer device context
-
Stops spooling a print job on a printer device context
-
Cancels print job on a printer device context
-
Starts a page on a printer device context
-
Ends a page on a printer device context
-
Copies the specified bytes to the specified printer. StartDocPrinter and EndDocPrinter should be called before and after. Returns number of bytes written to printer.
-
Enumerates print jobs on specified printer.
-
Returns dictionary of information about a specified print job.
-
Pause, cancel, resume, set priority levels on a print job.
-
Changes printer configuration
-
List printer providers for specified server and environment
-
Lists data types that specified print provider supports
-
Lists installed printer drivers
-
Lists forms for a printer
-
Adds a form for a printer
-
Deletes a form defined for a printer
-
Retrieves information about a defined form
-
Change information for a form
-
Adds a job to be spooled to a printer queue
-
Schedules a spooled job to be printed
-
Queries a printer for its capabilities
-
Retrieves device-specific parameters and settings
-
Lists installed printer port monitors
-
Lists printer ports on a server
-
Returns the directory where print processor files reside
-
Returns the directory where printer drivers are installed
-
Adds a new printer on a server
-
Deletes an existing printer
-
Deletes the specified driver from a server
-
Deletes a printer driver and associated files
-
Clears printer from error state if WritePrinter fails
win32print.AbortDoc
AbortDoc(hdc) Cancels a print job
-
hdc : PyHANDLE
Printer device context handle as returned by win32gui::CreateDC
win32print.AbortPrinter
AbortPrinter(hPrinter) Deletes spool file for a printer
-
hPrinter : PyPrinterHANDLE
Handle to printer as returned by win32print::OpenPrinter
win32print.AddForm
AddForm(hprinter, Form) Adds a form for a printer
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
-
Form : dict
FORM_INFO_1 dictionary
Returns None on success, throws an exception otherwise
win32print.AddJob
AddJob(hprinter) Add a job to be spooled to a printer queue
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
Returns the file name to which data should be written and the job id of the new job
win32print.AddPrinter
PyPrinterHANDLE = AddPrinter(Name, Level
, pPrinter
) Installs a printer on a server
-
Name : string
Name of server on which to install printer, None indicates local machine
-
Level : int
Level of data contained in pPrinter, only level 2 currently supported
-
pPrinter : dict
PRINTER_INFO_2 dict as returned by win32print::GetPrinter
pPrinterName, pPortName, pDriverName, and pPrintProcessor are required
Returns a handle to the new printer
win32print.AddPrinterConnection
None = AddPrinterConnection(printer) Connects to remote printer
-
printer : string
printer to connect to (eg: \\server\\printer).
win32print.ClosePrinter
ClosePrinter(hPrinter) Closes a handle to a printer.
-
hPrinter : PyPrinterHANDLE
handle to printer object
win32print.DeleteForm
DeleteForm(hprinter, FormName) Deletes a form defined for a printer
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
-
FormName : PyUnicode
Name of form to be deleted
Returns None on success, throws an exception otherwise
win32print.DeletePrinter
DeletePrinter(hPrinter) Deletes an existing printer
-
hPrinter : PyPrinterHANDLE
Handle to printer as returned by win32print::OpenPrinter or win32print::AddPrinter
Printer handle must be opened for PRINTER_ACCESS_ADMINISTER
If there are any pending print jobs for the printer, actual deletion does not happen until they are done
win32print.DeletePrinterConnection
None = DeletePrinterConnection(printer) Removes connection to remote printer
-
printer : string
printer to disconnect from (eg: \\server\\printer).
win32print.DeletePrinterDriver
DeletePrinterDriver(Server, Environment, DriverName) Removes the specified printer driver from a server
-
Server : string/PyUnicode
Name of print server, use None for local machine
-
Environment : string/PyUnicode
Environment - eg 'Windows NT x86' - use None for current client environment
-
DriverName : string/PyUnicode
Name of driver to remove
Does not delete associated driver files - use win32print::DeletePrinterDriverEx if this is required
win32print.DeletePrinterDriverEx
DeletePrinterDriverEx(Server, Environment, DriverName, DeleteFlag, VersionFlag) Deletes a printer driver and its associated files
-
Server : string/PyUnicode
Name of print server, use None for local machine
-
Environment : string/PyUnicode
Environment - eg 'Windows NT x86' - use None for current client environment
-
DriverName : string/PyUnicode
Name of driver to remove
-
DeleteFlag : int
Combination of DPD_DELETE_SPECIFIC_VERSION, DPD_DELETE_UNUSED_FILES, and DPD_DELETE_ALL_FILES
-
VersionFlag : int
Can be 0,1,2, or 3. Only used if DPD_DELETE_SPECIFIC_VERSION is specified in DeleteFlag
win32print.DeviceCapabilities
DeviceCapabilities(Device, Port, Capability, DEVMODE) Queries a printer for its capabilities
-
Device : string
Name of printer
-
Port : string
Port that printer is using
-
Capability : int
Type of capability to return - DC_* constant
-
DEVMODE=None : PyDEVMODE
If present, function returns values from it, otherwise the printer defaults are used
win32print.DocumentProperties
int = DocumentProperties(HWnd, hPrinter
, DeviceName
, DevModeOutput
, DevModeInput
, Mode
) Changes printer configuration for a printer
-
HWnd : PyHANDLE
Parent window handle to use if DM_IN_PROMPT is specified to display printer dialog
-
hPrinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
-
DeviceName : string
Name of printer
-
DevModeOutput : PyDEVMODE
PyDEVMODE object that receives modified info, can be None if DM_OUT_BUFFER not specified
-
DevModeInput : PyDEVMODE
PyDEVMODE that specifies initial configuration, can be None if DM_IN_BUFFER not specified
-
Mode : int
A combination of DM_IN_BUFFER, DM_OUT_BUFFER, and DM_IN_PROMPT - pass 0 to retrieve driver data size
If DM_IN_PROMPT is specified, returned value will be IDOK or IDCANCEL
win32print.EndDoc
EndDoc(hdc) Stops spooling a print job on a printer device context
-
hdc : PyHANDLE
Printer device context handle as returned by win32gui::CreateDC
win32print.EndDocPrinter
None = EndDocPrinter(hPrinter) The EndDocPrinter function ends a print job for the specified printer. To be used after using WritePrinter.
-
hPrinter : PyPrinterHANDLE
handle to printer (from win32print::OpenPrinter)
win32print.EndPage
EndPage(hdc) Ends a page on a printer device context
-
hdc : PyHANDLE
Printer device context handle as returned by win32gui::CreateDC
win32print.EndPagePrinter
EndPagePrinter(hprinter) Ends a page in a print job
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
win32print.EnumForms
(FORM_INFO_1,...) = EnumForms(hprinter) Lists forms for a printer
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
Returns a sequence of dictionaries representing FORM_INFO_1 structures
win32print.EnumJobs
tuple = EnumJobs(hPrinter, FirstJob
, NoJobs
, Level
) Enumerates print jobs on specified printer.
-
hPrinter : PyPrinterHANDLE
Handle of printer.
-
FirstJob : int
location of first job in print queue to enumerate.
-
NoJobs : int
Number of jobs to enumerate.
-
Level=1 : int
Level of information to return (JOB_INFO_1, JOB_INFO_2, JOB_INFO_3 supported).
Returns a sequence of dictionaries representing JOB_INFO_* structures, depending on level
win32print.EnumMonitors
(dict,...) = EnumMonitors(Name, Level
) Lists installed printer port monitors
-
Name : str/PyUnicode
Name of server, use None for local machine
-
Level : int
Level of information to return, 1 and 2 supported
Returns a sequence of dicts representing MONITOR_INFO_* structures depending on level
win32print.EnumPorts
(dict,...) = EnumPorts(Name, Level
) Lists printer port on a server
-
Name : str/PyUnicode
Name of server, use None for local machine
-
Level : int
Level of information to return, 1 and 2 supported
Returns a sequence of dicts representing PORT_INFO_* structures depending on level
win32print.EnumPrintProcessorDatatypes
(PyUnicode,...) = EnumPrintProcessorDatatypes(ServerName, PrintProcessorName
) List data types that specified print provider recognizes
-
ServerName : string/PyUnicode
Name of print server, use None for local machine
-
PrintProcessorName : string/PyUnicode
Name of print processor
win32print.EnumPrintProcessors
(PyUnicode,...) = EnumPrintProcessors(Server, Environment
) List printer processors for specified server and environment
-
Server=None : string/PyUnicode
Name of print server, use None for local machine
-
Environment=None : string/PyUnicode
Environment - eg 'Windows NT x86' - use None for current client environment
win32print.EnumPrinterDrivers
(dict,...) = EnumPrinterDrivers(Server, Environment
, Level
) Lists installed printer drivers
-
Server=None : string/unicode
Name of print server, use None for local machine
-
Environment=None : string/unicode
Environment - eg 'Windows NT x86' - use None for current client environment
-
Level=1 : int
Level of information to return, 1-6 (not all levels are supported on all platforms)
On Win2k and up, 'all' can be passed for environment
Returns a sequence of dictionaries representing DRIVER_INFO_* structures
win32print.EnumPrinters
tuple = EnumPrinters(flags, name
, level
) Enumerates printers, print servers, domains and print providers.
-
flags : int
types of printer objects to enumerate (combination of PRINTER_ENUM_* constants).
-
name=None : string
name of printer object.
-
level=1 : int
type of printer info structure (Levels 1,2,4,5 supported)
Use Flags=PRINTER_ENUM_NAME, Name=None, Level=1 to enumerate print providers.
Use Flags=PRINTER_ENUM_NAME, Name=\\servername, Level=2 or 5 to list printers on another server.
See MSDN docs for EnumPrinters for other specific combinations
Level 1 returns a tuple of tuples for backward compatibility.
Each individual element is a tuple of (flags, description, name, comment)
All other levels return a tuple of dictionaries representing PRINTER_INFO_* structures
win32print.FlushPrinter
int = FlushPrinter(Printer, Buf
, Sleep
) Clears printer from error state if WritePrinter fails
-
Printer : PyPrinterHANDLE
Handle to a printer
-
Buf : str
Data to be sent to printer
-
Sleep : int
Number of milliseconds to suspend printer
Returns the number of bytes actually written to the printer
win32print.GetDefaultPrinter
string = GetDefaultPrinter() Returns the default printer.
win32print.GetDefaultPrinterW
PyUnicode = GetDefaultPrinterW() Returns the default printer.
Unlike win32print::GetDefaultPrinter, this method calls the GetDefaultPrinter API function.
win32print.GetDeviceCaps
int = GetDeviceCaps(hdc, Index
) Retrieves device-specific parameters and settings
-
hdc : PyHANDLE
Handle to a printer or display device context
-
Index : int
The capability to return. See MSDN for valid values.
Can also be used for Display DCs in addition to printer DCs
- Search for GetDeviceCaps at msdn, google or google groups.
win32print.GetForm
GetForm(hprinter, FormName) Retrieves information about a form defined for a printer
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
-
FormName : PyUnicode
Name of form for which to retrieve info
Returns a FORM_INFO_1 dict
win32print.GetJob
dictionary = GetJob(hPrinter, JobID
, Level
) Returns dictionary of information about a specified print job.
-
hPrinter : PyPrinterHANDLE
Handle to a printer as returned by win32print::OpenPrinter.
-
JobID : int
Job Identifier.
-
Level=1 : int
Level of information to return (JOB_INFO_1, JOB_INFO_2, JOB_INFO_3 supported).
Returns a dict representing a JOB_INFO_* struct, depending on level
win32print.GetPrintProcessorDirectory
PyUnicode = GetPrintProcessorDirectory(Name, Environment
) Returns the directory where print processor files reside
-
Name : str/PyUnicode
Name of server, use None for local machine
-
Environment : str/PyUnicode
Environment - eg 'Windows NT x86' - use None for current client environment
win32print.GetPrinter
dict = GetPrinter(hPrinter, Level
) Retrieves information about a printer
-
hPrinter : PyPrinterHANDLE
handle to printer object as returned by win32print::OpenPrinter
-
Level=2 : int
Level of data returned (1,2,3,4,5,7,8,9)
Original implementation used level 2 only and returned a tuple
Pass single arg as indicator to use old behaviour for backward compatibility
Returns a dictionary containing PRINTER_INFO_* data for level, or
returns a tuple of PRINTER_INFO_2 data if no level is passed in.
win32print.GetPrinterDriverDirectory
PyUnicode = GetPrinterDriverDirectory(Name, Environment
) Returns the directory where printer drivers are installed
-
Name : str/PyUnicode
Name of server, use None for local machine
-
Environment : str/PyUnicode
Environment - eg 'Windows NT x86' - use None for current client environment
win32print.OpenPrinter
PyPrinterHANDLE = OpenPrinter(printer, Defaults
) Retrieves a handle to a printer.
-
printer : string
Printer or print server name. Use None to open local print server.
-
Defaults=None : dict
PRINTER_DEFAULTS dict, or None
win32print.ScheduleJob
ScheduleJob(hprinter, JobId) Schedules a spooled job to be printed
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
-
JobId : int
Job Id as returned by win32print::AddJob
win32print.SetDefaultPrinter
None = SetDefaultPrinter(printer) Sets the default printer.
-
printer : string
printer to set as default
This function uses the pre-win2k method of WriteProfileString rather than the SetDefaultPrinter API function
win32print.SetDefaultPrinterW
None = SetDefaultPrinterW(Printer) Sets the default printer
-
Printer : PyUnicode
Name of printer, can be None to use first available printer
Unlike win32print::SetDefaultPrinter, this method calls the SetDefaultPrinter API function.
win32print.SetForm
SetForm(hprinter, FormName, Form) Change information for a form
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
-
FormName : PyUnicode
Name of form
-
Form : dict
FORM_INFO_1 dictionary
Returns None on success
win32print.SetJob
None = SetJob(hPrinter, JobID
, Level
, JobInfo
, Command
) Pause, cancel, resume, set priority levels on a print job.
-
hPrinter : PyPrinterHANDLE
Handle of printer.
-
JobID : int
Job Identifier.
-
Level : int
Level of information in JobInfo dict (0, 1, 2, and 3 are supported).
-
JobInfo : dict
JOB_INFO_* Dictionary as returned by win32print::GetJob or win32print::EnumJobs (can be None if Level is 0).
-
Command : int
Job command value (JOB_CONTROL_*).
If printer is not opened with at least PRINTER_ACCESS_ADMINISTER access, 'Position' member of
JOB_INFO_1 and JOB_INFO_2 must be set to JOB_POSITION_UNSPECIFIED
win32print.SetPrinter
SetPrinter(hPrinter, Level, pPrinter, Command) Change printer configuration and status
-
hPrinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
-
Level : int
Level of data contained in pPrinter
-
pPrinter : dict
PRINTER_INFO_* dict as returned by win32print::GetPrinter, can be None if level is 0
-
Command : int
Command to send to printer - one of the PRINTER_CONTROL_* constants, or 0
If Level is 0 and Command is PRINTER_CONTROL_SET_STATUS, pPrinter should be an integer,
and is interpreted as the new printer status to set (one of the PRINTER_STATUS_* constants).
win32print.StartDoc
int = StartDoc(hdc, docinfo
) Starts spooling a print job on a printer device context
-
hdc : PyHANDLE
Printer device context handle as returned by win32gui::CreateDC
-
docinfo : tuple
DOCINFO tuple specifying print job parameters
On success, returns the job id of the print job
win32print.StartDocPrinter
int = StartDocPrinter(hprinter, level
, tuple
) Notifies the print spooler that a document is to be spooled for printing. To be used before using WritePrinter. Returns the Jobid of the started job.
-
hprinter : PyPrinterHANDLE
handle to printer (from win32print::OpenPrinter)
-
level=1 : int
type of docinfo structure (only docinfo level 1 supported)
-
tuple : data
A tuple corresponding to the level parameter.
For level 1, the tuple is:
-
[0] string : docName
Specifies the name of the document.
-
[1] string : outputFile
Specifies the name of an output file. To print to a printer, set this to None.
-
[2] string : dataType
Identifies the type of data used to record the document, such
as "raw" or "emf", used to record the print job. This member can be None. If it is not None,
the StartDoc function passes it to the printer driver. Note that the printer driver might
ignore the requested data type.
win32print.StartPage
StartPage(hdc) Starts a page on a printer device context
-
hdc : PyHANDLE
Printer device context handle as returned by win32gui::CreateDC
win32print.StartPagePrinter
StartPagePrinter(hprinter) Notifies the print spooler that a page is to be printed on specified printer
-
hprinter : PyPrinterHANDLE
Printer handle as returned by win32print::OpenPrinter
win32print.WritePrinter
int = WritePrinter(hprinter, buf
) Copies the specified bytes to the specified printer.
Suitable for copying raw Postscript or HPGL files to a printer.
StartDocPrinter and EndDocPrinter should be called before and after.
-
hprinter : PyPrinterHANDLE
Handle to printer as returned by win32print::OpenPrinter.
-
buf : string
String or buffer containing data to send to printer. Embedded NULL bytes are allowed.
Returns number of bytes written to printer.