Detect all paper size the printer supports

G

Guest

Hi,
Is it possible to detect all paper that given printer support? For example,
I would like to check whether my printer can print A4 and A3 or not.

Regards
Tran Hong Quang
 
D

Dirk Goldgar

Tran Hong Quang said:
Hi,
Is it possible to detect all paper that given printer support? For
example, I would like to check whether my printer can print A4 and A3
or not.

I've never tried it before, but apparently you can call the
DeviceCapabilities API function to find this out. The code would be
something like this, which I modified from the API guide provided by
AllAPI.Net:

'----- start of code -----
Private Const DC_PAPERNAMES = 16

Private Declare Function DeviceCapabilities _
Lib "winspool.drv" Alias "DeviceCapabilitiesA" _
(ByVal lpDeviceName As String, _
ByVal lpPort As String, _
ByVal iIndex As Long, _
lpOutput As Any, _
lpDevMode As Any) _
As Long

Sub GetPaperNames()

' This procedure prints the supported paper sizes, by name, to the
' Immediate window. Modify as needed.

Dim Ret As Long
Dim PaperSizes() As Byte
Dim Cnt As Long
Dim AllNames As String
Dim lStart As Long, lEnd As Long

'Retrieve the number of available paper names
Ret = DeviceCapabilities( _
Printer.DeviceName, _
"LPT1", _
DC_PAPERNAMES, _
ByVal 0&, _
ByVal 0&)

'resize the array
ReDim PaperSizes(1 To Ret * 64) As Byte

'retrieve all the available paper names
Call DeviceCapabilities( _
Printer.DeviceName, _
"LPT1", _
DC_PAPERNAMES, _
PaperSizes(1), _
ByVal 0&)

Debug.Print "Supported papersizes:"

'convert the retrieved byte array to a string
AllNames = StrConv(PaperSizes, vbUnicode)

'loop through the string and search for the names of the papers
Do
lEnd = InStr(lStart + 1, AllNames, Chr$(0), vbBinaryCompare)
If (lEnd > 0) And (lEnd - lStart - 1 > 0) Then
Debug.Print Mid$(AllNames, lStart + 1, lEnd - lStart - 1)
End If
lStart = lEnd
Loop Until lEnd = 0

End Sub
'----- end of code -----
 

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

Top