如何获取斑马打印机的当前标签尺寸设置



我正在制作一个访问应用程序,可以打印两种尺寸的标签,3"宽乘2"高,然后1.5"宽乘1"高。此应用程序将在几台没有相同打印机集的不同计算机上运行,例如,机器 1 可能有一台 GC420d、一台 GK420d 和一台普通的 8.5x11 打印机,然后机器 2 可能有一台 LP 2844、一台 GC420d 和一台普通的 8.5x11 打印机。机器分布在整个生产环境中,我们无法对打印机类型进行标准化。因此,这让我需要能够确定哪台打印机具有 3" x 2" 设置,哪个打印机具有 1.5" x 1" 设置。

编辑:我知道这看起来像"我什么都没尝试过,我懒得尝试"的情况,但是当访问崩溃到桌面时,我拥有的所有代码都丢失了。我主要尝试了Win API的东西,比如DeviceCapabilities,但我无法让它给我任何有用的东西。纸张类型 当我看不到自定义纸张类型的实际尺寸时,自定义枚举是无用的。然后我尝试了DocumentProperties,它需要OpenPrinter来获取打印机句柄。这就是破坏一切访问方面的东西。我用了这个 网站以获取对 VBA 的 API 调用。

编辑2:这是根据访问返回的纸张类型。

?application.Printers(0).DeviceName
ZDesigner GC420d (EPL)
?application.Printers(0).PaperSize
256 

您可以使用以下内容列出所有支持的纸张名称及其相应的大小:

Private Enum DeviceCapabilitiesFlags
DC_FIELDS = 1
DC_PAPERS = 2
DC_PAPERSIZE = 3
DC_MINEXTENT = 4
DC_MAXEXTENT = 5
DC_BINS = 6
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
DC_MEDIATYPENAMES = 34
DC_MEDIATYPES = 35
End Enum
Private Type POINT
x As Long
y As Long
End Type
Private Declare Function DeviceCapabilities _
Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" _
(ByVal lpDeviceName As String, _
ByVal lpPort As String, _
ByVal iIndex As Long, _
ByRef lpOutput As Any, _
ByRef lpDevMode As Any) _
As Long
Private Declare Function StrLen _
Lib "kernel32.dll" _
Alias "lstrlenA" _
(ByVal lpString As String) _
As Long
Public Sub ListSupportedPaperSizes()
Dim defaultPrinter() As String
Dim paperCount As Long
Dim NameArray() As Byte
Dim i As Long
Dim paperNames() As String
Dim paperName As String
Dim ctr As Long
defaultPrinter = Split(Application.ActivePrinter, " on ")
paperCount = DeviceCapabilities(defaultPrinter(0), defaultPrinter(1), DC_PAPERSIZE, ByVal 0&, ByVal 0&)
ReDim paperNames(1 To paperCount)
ReDim NameArray(0 To paperCount * 64) As Byte
' Get paper names
paperCount = DeviceCapabilities(defaultPrinter(0), defaultPrinter(1), DC_PAPERNAMES, NameArray(0), 0)
'convert the retrieved byte array to an ANSI string
AllNames = StrConv(NameArray, vbUnicode)
ReDim paperNames(1 To paperCount)
'loop through the string and search for the names of the papers
For i = 1 To Len(AllNames) Step 64
ctr = ctr + 1
paperName = Mid(AllNames, i, 64)
paperName = Left(paperName, StrLen(paperName))
If paperName <> vbNullString Then
paperNames(ctr) = paperName
End If
Next i
ReDim PaperSizes(1 To paperCount) As POINT
paperCount = DeviceCapabilities(defaultPrinter(0), defaultPrinter(1), DC_PAPERSIZE, PaperSizes(1), 0)
For i = 1 To paperCount
Debug.Print paperNames(i) & " : " _
& Format(PaperSizes(i).x / 254, "0.00") & " x " _
& Format(PaperSizes(i).y / 254, "0.00") _
& " inch"
Next
End Sub

最新更新