我试图做设置自定义纸张尺寸:打印机页面大小问题
Printer.Height = 2160
Printer.Width = 11900
但它并没有看到有任何效果。设置完这些之后,我要求这些值,它会返回默认值。而这个:
Printer.PaperSize = 256
返回一个错误...
任何想法?
我试图做设置自定义纸张尺寸:打印机页面大小问题
Printer.Height = 2160
Printer.Width = 11900
但它并没有看到有任何效果。设置完这些之后,我要求这些值,它会返回默认值。而这个:
Printer.PaperSize = 256
返回一个错误...
任何想法?
的解决方案是使用Windows 98的它不WIN2K工作,不是winXP。相同的代码,相同的打印机。
Regards。
您的打印机不允许设置这些属性,或者您超出了允许的最大值。从Visual Basic Reference
如果设置的高度和宽度 属性的打印机驱动程序 不允许这些属性是 一套,没有出现错误和 的纸张尺寸保持原样。如果 设置打印机的高度和宽度 驱动程序只允许指定某些值 ,则不会发生错误,并且 该属性设置为 驱动程序允许的任何值。例如,你可以 一套高度为150,司机会 将其设置为144
我不知道为什么你会得到一个错误,当您的纸张大小属性设置为256。它适用于我。另外,the documentation指出“设置打印机的高度或宽度属性会自动将PaperSize设置为vbPRPSUser。”,等于256.
确定该错误与打印机本身的最大打印宽度无关?许多打印机的最大打印宽度为8.25英寸(11880),允许在8.5英寸宽的纸张的任一侧上留出1/4“边距。
最快的检查方法是将打印宽度设置为11880或更低看看它是否工作。
另一种可能性是权限的打印机。如果它是一个共享的网络资源,可能会被锁定。
我实际上参与了同样的问题,但我碰巧找到了一个突破。 首先,您需要创建一个定义您自定义纸张尺寸的自定义表格。然后,您需要 参考Windows API来检查您刚刚创建的表单名称。您将从函数返回的数组中获得名称 ,并使用找到表单名称的数组索引。 最后把它作为价值printer.papersize低于
例子:
Public Type PRINTER_DEFAULTS
pDatatype As Long
pDevMode As Long
DesiredAccess As Long
End Type
Public Type FORM_INFO_1
Flags As Long
pName As Long ' String
Size As SIZEL
ImageableArea As RECTL
End Type
Public Declare Function EnumForms Lib "winspool.drv" Alias "EnumFormsA" _
(ByVal hPrinter As Long, ByVal Level As Long, ByRef pForm As Any, _
ByVal cbBuf As Long, ByRef pcbNeeded As Long, _
ByRef pcReturned As Long) As Long
Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" _
(pDest As Any, pSource As Any, ByVal cbLength As Long)
Public Declare Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)
Public Declare Function OpenPrinter Lib "winspool.drv" Alias _
"OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
pDefault As PRINTER_DEFAULTS) As Long
Public Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Public Declare Function lstrcpy Lib "KERNEL32" Alias "lstrcpyA" _
(ByVal lpString1 As String, ByRef lpString2 As Long) As Long
'UDF
Public Function PtrCtoVbString(ByVal Add As Long) As String
Dim sTemp As String * 512, x As Long
x = lstrcpy(sTemp, ByVal Add)
If (InStr(1, sTemp, Chr(0)) = 0) Then
PtrCtoVbString = ""
Else
PtrCtoVbString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1)
End If
End Function
Public Function IsFormExist(ByVal DeviceName As String, ByVal isFormName As String, ByVal PrinterHandle As Long) As Long
Dim NumForms As Long, i As Long
Dim FI1 As FORM_INFO_1
Dim pd As PRINTER_DEFAULTS
Dim aFI1() As FORM_INFO_1 ' Working FI1 array
Dim Temp() As Byte ' Temp FI1 array
Dim FormIndex As Integer
Dim BytesNeeded As Long
Dim RetVal As Long
On Error GoTo cleanup
FormIndex = 0
ReDim aFI1(1)
' First call retrieves the BytesNeeded.
RetVal = OpenPrinter(DeviceName, PrinterHandle, pd)
If (RetVal = 0) Or (PrinterHandle = 0) Then
'Can't access current printer. Bail out doing nothing
Exit Function
End If
RetVal = EnumForms(PrinterHandle, 1, aFI1(0), 0&, BytesNeeded, NumForms)
ReDim Temp(BytesNeeded)
ReDim aFI1(BytesNeeded/Len(FI1))
' Second call actually enumerates the supported forms.
RetVal = EnumForms(PrinterHandle, 1, Temp(0), BytesNeeded, BytesNeeded, _
NumForms)
Call CopyMemory(aFI1(0), Temp(0), BytesNeeded)
For i = 0 To NumForms - 1
With aFI1(i)
If isFormName = PtrCtoVbString(.pName) Then
' Found the desired form
FormIndex = i + 1
Exit For
End If
End With
Next i
IsFormExist = FormIndex ' Returns the number when form is found.
cleanup:
'Release the printer handle
If (PrinterHandle <> 0) Then Call ClosePrinter(PrinterHandle)
End Function
'Here We Go
dim papercode as long, printername as string, formname as string
printername=printer.Devicename
formname = "myform"
papercode=IsFormExist(printername, formname, Printer.hdc)
if papercode<>0 then
printer.papersize=papercode
end if
试试吧,祝你好运
我测试的代码,但我不能看到自定义我在控制面板Windows XP Professional SP3中使用打印机和扫描仪创建的表单。 注意:我可以在regedit中检查这个表单是否存在,其ID是512,并且它包含在打印机控制面板中创建的表单的名称。
为什么此功能不返回我的自定义格式,我正在使用HP Laserjet 1020.