Set Printer Using Printing API
-
I have found this code to set printer properties using Windows API: Controlling the Printer from Word VBA[^] which is basically a further development of Microsoft's article: HOWTO: Set Duplex Printing for Word Automation[^] I want to ask whether any of you guys have done or have any ideas on how to set printer stapling using the code above. I am thinking of creating a new constant for the stapling, e.g. Public Const DM_DUPLEX = &H1000& Public Const DM_STAPLE = &H2000& '(added line) and add a new variable in the DEVMODE Type: Public Type DEVMODE dmStaple as integer End Type then set the dmStaple and set it to the printer using the API, but somehow I don't think it is going to work at all. Question: 1. Can I set printer stapling using the API mentioned in the sites above? 2. If I can, can I do it like the above? If not, can you please point me to the right direction (e.g. giving a link to SDK site / MSDN article, code snippets, etc.) Thanks. Edbert P. Sydney, Australia.
-
I have found this code to set printer properties using Windows API: Controlling the Printer from Word VBA[^] which is basically a further development of Microsoft's article: HOWTO: Set Duplex Printing for Word Automation[^] I want to ask whether any of you guys have done or have any ideas on how to set printer stapling using the code above. I am thinking of creating a new constant for the stapling, e.g. Public Const DM_DUPLEX = &H1000& Public Const DM_STAPLE = &H2000& '(added line) and add a new variable in the DEVMODE Type: Public Type DEVMODE dmStaple as integer End Type then set the dmStaple and set it to the printer using the API, but somehow I don't think it is going to work at all. Question: 1. Can I set printer stapling using the API mentioned in the sites above? 2. If I can, can I do it like the above? If not, can you please point me to the right direction (e.g. giving a link to SDK site / MSDN article, code snippets, etc.) Thanks. Edbert P. Sydney, Australia.
First you need to find out if the printer supports stapling at all by calling the Api GetDeviceCaps with the index DC_STAPLE.
Public Enum PrintDeviceCapabilitiesIndexes ' ##ENUMERATION_MEMBER_DESCRIPTION DC_FIELDS Which fields of the device mode are used DC_FIELDS = 1 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_PAPERS Which Printer Paper Sizes the device supports DC_PAPERS = 2 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_PAPERSIZE The dimensions of the paper in 10ths of a millimeter DC_PAPERSIZE = 3 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_MINEXTENT The minimum paper width and height the printer can support DC_MINEXTENT = 4 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_MAXEXTENT The maximum paper width and height the printer can support DC_MAXEXTENT = 5 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_BINS The standard paper bins supported by this printer DC_BINS = 6 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_DUPLEX Whether the printer supports duplex printing DC_DUPLEX = 7 DC_SIZE = 8 DC_EXTRA = 9 DC_VERSION = 10 DC_DRIVER = 11 DC_BINNAMES = 12 DC_ENUMRESOLUTIONS = 13 DC_FILEDEPENDENCIES = 14 DC_TRUETYPE = 15 DC_PAPERNAMES = 16 DC_ORIENTATION = 17 DC_COPIES = 18 DC_BINADJUST = 19 DC_EMF_COMPLIANT = 20 DC_DATATYPE_PRODUCED = 21 DC_COLLATE = 22 DC_MANUFACTURER = 23 DC_MODEL = 24 DC_PERSONALITY = 25 DC_PRINTRATE = 26 DC_PRINTRATEUNIT = 27 DC_PRINTERMEM = 28 DC_MEDIAREADY = 29 DC_STAPLE = 30 DC_PRINTRATEPPM = 31 DC_COLORDEVICE = 32 DC_NUP = 33 End Enum Private Declare Function DeviceCapabilities Lib "winspool.drv" Alias "DeviceCapabilitiesA" (ByVal DeviceName As String, ByVal Portname As String, ByVal Index As PrintDeviceCapabilitiesIndexes, ByVal lpBuf As Long, pDevMode As Long) As Long
... '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd -
First you need to find out if the printer supports stapling at all by calling the Api GetDeviceCaps with the index DC_STAPLE.
Public Enum PrintDeviceCapabilitiesIndexes ' ##ENUMERATION_MEMBER_DESCRIPTION DC_FIELDS Which fields of the device mode are used DC_FIELDS = 1 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_PAPERS Which Printer Paper Sizes the device supports DC_PAPERS = 2 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_PAPERSIZE The dimensions of the paper in 10ths of a millimeter DC_PAPERSIZE = 3 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_MINEXTENT The minimum paper width and height the printer can support DC_MINEXTENT = 4 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_MAXEXTENT The maximum paper width and height the printer can support DC_MAXEXTENT = 5 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_BINS The standard paper bins supported by this printer DC_BINS = 6 ' ##ENUMERATION_MEMBER_DESCRIPTION DC_DUPLEX Whether the printer supports duplex printing DC_DUPLEX = 7 DC_SIZE = 8 DC_EXTRA = 9 DC_VERSION = 10 DC_DRIVER = 11 DC_BINNAMES = 12 DC_ENUMRESOLUTIONS = 13 DC_FILEDEPENDENCIES = 14 DC_TRUETYPE = 15 DC_PAPERNAMES = 16 DC_ORIENTATION = 17 DC_COPIES = 18 DC_BINADJUST = 19 DC_EMF_COMPLIANT = 20 DC_DATATYPE_PRODUCED = 21 DC_COLLATE = 22 DC_MANUFACTURER = 23 DC_MODEL = 24 DC_PERSONALITY = 25 DC_PRINTRATE = 26 DC_PRINTRATEUNIT = 27 DC_PRINTERMEM = 28 DC_MEDIAREADY = 29 DC_STAPLE = 30 DC_PRINTRATEPPM = 31 DC_COLORDEVICE = 32 DC_NUP = 33 End Enum Private Declare Function DeviceCapabilities Lib "winspool.drv" Alias "DeviceCapabilitiesA" (ByVal DeviceName As String, ByVal Portname As String, ByVal Index As PrintDeviceCapabilitiesIndexes, ByVal lpBuf As Long, pDevMode As Long) As Long
... '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd... However the structure DEVMODE is defined by the windows header file and you cannot change it....and unfortunately it does not have a dmStaple member. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd
-
... However the structure DEVMODE is defined by the windows header file and you cannot change it....and unfortunately it does not have a dmStaple member. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd