Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Set Printer Using Printing API

Set Printer Using Printing API

Scheduled Pinned Locked Moved Visual Basic
questioncomtestingtools
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Edbert P
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • E Edbert P

      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.

      D Offline
      D Offline
      Duncan Edwards Jones
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • D Duncan Edwards Jones

        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

        D Offline
        D Offline
        Duncan Edwards Jones
        wrote on last edited by
        #3

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

        E 1 Reply Last reply
        0
        • D Duncan Edwards Jones

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

          E Offline
          E Offline
          Edbert P
          wrote on last edited by
          #4

          Thanks for that, Duncan. Can you please give me a suggestion on what I should investigate to set the printer stapling? (API, PCL Printer Commands, PJL, etc.) Edbert P. Sydney, Australia.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups