针式打印机走纸问题

cqmi2009 2009-09-07 10:16:24
1.针式打印机,型号dpk8300e+
2.纸张ABC 24.1*9.3,已全部设置OK
3.打印机首选项中纸张已设为ABC
4.测试程序:

dim i as long
for i=1 to 5
printer.newpage
next

5.结果
打印机走纸5页短2.5厘米

改如何调整,或该用什么方法控制打印机走纸?
...全文
2495 42 打赏 收藏 转发到动态 举报
写回复
用AI写文章
42 条回复
切换为时间正序
请发表友善的回复…
发表回复
dfzone 2011-11-24
  • 打赏
  • 举报
回复
我也遇到同样的问题,我的打印机型号是爱普生LQ-2680K,我发现我使用用户自定义纸张用链式纸打印时候,似乎没有效果,每次似乎走的是A4纸的高度,真是郁闷~期待高手指点~
熊孩子开学喽 2010-02-01
  • 打赏
  • 举报
回复
[Quote=引用楼主 cqmi2009 的回复:]
...
打印机走纸5页短2.5厘米
...[/Quote]
很说明问题了: 你设的纸张长度不精确. 测量和设定纸张长度是非常重要的,特别是对于票据类连续走纸的打印. 科学的做法是拿没有打印过的连续的新纸张,测量多张纸的总长度,再除以张数. 比如你量一下10张连续的新纸总长度,测量到的结果除以10,基本就正确了. 至少连续打几百张是不会有问题的.
kinggqc 2009-09-18
  • 打赏
  • 举报
回复
我现在也遇到了你说的刚开始的问题,
我在页面的最低端打印一条横线,结果是横线离纸张最下端有5毫米的距离。
连续打印5张后横线离纸张最下端已经2.5厘米了
请教你现在的办法
主要是代码怎么写啊 、
不胜感谢,现在我的打印机还在用手拧呢
麻烦死了
email:king_gqc@163.com
Obj_GetFile 2009-09-10
  • 打赏
  • 举报
回复
Public Type DEVMODE
dmDeviceName As String * CCHDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCHFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

Public Type PRINTER_DEFAULTS
pDatatype As String
pDevMode As Long ' DEVMODE
DesiredAccess As Long
End Type

Public Type PRINTER_INFO_2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pDevMode As DEVMODE
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As SECURITY_DESCRIPTOR
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type

Public Function GetFormName(ByVal PrinterHandle As Long, _
FormSize As SIZEL, FormName As String) As Integer
Dim NumForms As Long, I As Long
Dim FI1 As FORM_INFO_1
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

FormName = vbNullString
FormIndex = 0
ReDim aFI1(1)
' First call retrieves the BytesNeeded.
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 .Size.cx = FormSize.cx And .Size.cy = FormSize.cy Then
' Found the desired form
FormName = PtrCtoVbString(.pName)
FormIndex = I + 1
Exit For
End If
End With
Next I
GetFormName = FormIndex ' Returns non-zero when form is found.
End Function

Public Function AddNewForm(PrinterHandle As Long, FormSize As SIZEL, _
FormName As String) As String
Dim FI1 As sFORM_INFO_1
Dim aFI1() As Byte
Dim RetVal As Long

With FI1
.Flags = 0
.pName = FormName
With .Size
.cx = FormSize.cx
.cy = FormSize.cy
End With
With .ImageableArea
.Left = 0
.Top = 0
.Right = FI1.Size.cx
.Bottom = FI1.Size.cy
End With
End With
ReDim aFI1(Len(FI1))
Call CopyMemory(aFI1(0), FI1, Len(FI1))
RetVal = AddForm(PrinterHandle, 1, aFI1(0))
If RetVal = 0 Then
If Err.LastDllError = 5 Then
MsgBox "You do not have permissions to add a form to " & _
Printer.DeviceName, vbExclamation, "Access Denied!"
Else
MsgBox "Error: " & Err.LastDllError, "Error Adding Form"
End If
AddNewForm = "none"
Else
AddNewForm = FI1.pName
End If
End Function

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 SelectForm(FormName As String, ByVal MyhWnd As Long) _
As Integer
Dim nSize As Long ' Size of DEVMODE
Dim pDevMode As DEVMODE
Dim PrinterHandle As Long ' Handle to printer
Dim hPrtDC As Long ' Handle to Printer DC
Dim PrinterName As String
Dim aDevMode() As Byte ' Working DEVMODE
Dim FormSize As SIZEL

PrinterName = Printer.DeviceName ' Current printer
hPrtDC = Printer.hdc ' hDC for current Printer
SelectForm = FORM_NOT_SELECTED ' Set for failure unless reset in code.

' Get a handle to the printer.
If OpenPrinter(PrinterName, PrinterHandle, 0&) Then
' Retrieve the size of the DEVMODE.
nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, 0&, _
0&, 0&)
' Reserve memory for the actual size of the DEVMODE.
ReDim aDevMode(1 To nSize)

' Fill the DEVMODE from the printer.
nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, _
aDevMode(1), 0&, DM_OUT_BUFFER)
' Copy the Public (predefined) portion of the DEVMODE.
Call CopyMemory(pDevMode, aDevMode(1), Len(pDevMode))

' If FormName is "MyCustomForm", we must make sure it exists
' before using it. Otherwise, it came from our EnumForms list,
' and we do not need to check first. Note that we could have
' passed in a Flag instead of checking for a literal name.
If FormName = "MyCustomForm" Then
' Use form "MyCustomForm", adding it if necessary.
' Set the desired size of the form needed.
With FormSize ' Given in thousandths of millimeters
.cx = 214000 ' width
.cy = 216000 ' height
End With
If GetFormName(PrinterHandle, FormSize, FormName) = 0 Then
' Form not found - Either of the next 2 lines will work.
'FormName = AddNewForm(PrinterHandle, FormSize, "MyCustomForm")
AddNewForm PrinterHandle, FormSize, "MyCustomForm"
If GetFormName(PrinterHandle, FormSize, FormName) = 0 Then
ClosePrinter (PrinterHandle)
SelectForm = FORM_NOT_SELECTED ' Selection Failed!
Exit Function
Else
SelectForm = FORM_ADDED ' Form Added, Selection succeeded!
End If
End If
End If

' Change the appropriate member in the DevMode.
' In this case, you want to change the form name.
pDevMode.dmFormName = FormName & Chr(0) ' Must be NULL terminated!
' Set the dmFields bit flag to indicate what you are changing.
pDevMode.dmFields = DM_FORMNAME

' Copy your changes back, then update DEVMODE.
Call CopyMemory(aDevMode(1), pDevMode, Len(pDevMode))
nSize = DocumentProperties(MyhWnd, PrinterHandle, PrinterName, _
aDevMode(1), aDevMode(1), DM_IN_BUFFER Or DM_OUT_BUFFER)

nSize = ResetDC(hPrtDC, aDevMode(1)) ' Reset the DEVMODE for the DC.

' Close the handle when you are finished with it.
ClosePrinter (PrinterHandle)
' Selection Succeeded! But was Form Added?
If SelectForm <> FORM_ADDED Then SelectForm = FORM_SELECTED
Else
SelectForm = FORM_NOT_SELECTED ' Selection Failed!
End If
End Function

Public Sub PrintTest()
' Print two test pages to confirm the page size.
Printer.Print "Top of Page 1."
Printer.NewPage
' Spacing between lines should reflect the chosen page height.
Printer.Print "Top of Page 2. - Check the page Height (Length.)"
Printer.EndDoc
MsgBox "Check Printer " & Printer.DeviceName, vbInformation, "Done!"
End Sub
Obj_GetFile 2009-09-10
  • 打赏
  • 举报
回复
接着的代码。

Private Sub UseForm(FormName As String)
Dim RetVal As Integer

RetVal = SelectForm(FormName, Me.hwnd)
Select Case RetVal
Case FORM_NOT_SELECTED ' 0
' Selection failed!
MsgBox "Unable to retrieve From name", vbExclamation, _
"Operation halted!"
Case FORM_SELECTED ' 1
' Selection succeeded!
PrintTest ' Comment this line to avoid printing
Case FORM_ADDED ' 2
' Form added and selected.
List1.Clear ' Reflect the addition in the ListBox
Form_Load ' by rebuilding the list.
End Select
End Sub

在工程 菜单上,添加一个新模块,Module1。
将下面的代码粘贴到 Module1 中:
Option Explicit

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 Function AddForm Lib "winspool.drv" Alias "AddFormA" _
(ByVal hPrinter As Long, ByVal Level As Long, pForm As Byte) As Long

Public Declare Function DeleteForm Lib "winspool.drv" Alias "DeleteFormA" _
(ByVal hPrinter As Long, ByVal pFormName As String) As Long

Public Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, ByVal pDefault As Long) As Long

Public Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long

Public Declare Function DocumentProperties Lib "winspool.drv" _
Alias "DocumentPropertiesA" (ByVal hwnd As Long, _
ByVal hPrinter As Long, ByVal pDeviceName As String, _
pDevModeOutput As Any, pDevModeInput As Any, ByVal fMode As Long) _
As Long

Public Declare Function ResetDC Lib "gdi32" Alias "ResetDCA" _
(ByVal hdc As Long, lpInitData As Any) As Long

Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Public Declare Function lstrcpy Lib "KERNEL32" Alias "lstrcpyA" _
(ByVal lpString1 As String, ByRef lpString2 As Long) As Long

' Optional functions not used in this sample, but may be useful.
Public Declare Function GetForm Lib "winspool.drv" Alias "GetFormA" _
(ByVal hPrinter As Long, ByVal pFormName As String, _
ByVal Level As Long, pForm As Byte, ByVal cbBuf As Long, _
pcbNeeded As Long) As Long

Public Declare Function SetForm Lib "winspool.drv" Alias "SetFormA" _
(ByVal hPrinter As Long, ByVal pFormName As String, _
ByVal Level As Long, pForm As Byte) As Long

' Constants for DEVMODE
Public Const CCHFORMNAME = 32
Public Const CCHDEVICENAME = 32
Public Const DM_FORMNAME As Long = &H10000
Public Const DM_ORIENTATION = &H1&

' Constants for PRINTER_DEFAULTS.DesiredAccess
Public Const PRINTER_ACCESS_ADMINISTER = &H4
Public Const PRINTER_ACCESS_USE = &H8
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE)

' Constants for DocumentProperties() call
Public Const DM_MODIFY = 8
Public Const DM_IN_BUFFER = DM_MODIFY
Public Const DM_COPY = 2
Public Const DM_OUT_BUFFER = DM_COPY

' Custom constants for this sample's SelectForm function
Public Const FORM_NOT_SELECTED = 0
Public Const FORM_SELECTED = 1
Public Const FORM_ADDED = 2

Public Type RECTL
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Type SIZEL
cx As Long
cy As Long
End Type

Public Type SECURITY_DESCRIPTOR
Revision As Byte
Sbz1 As Byte
Control As Long
Owner As Long
Group As Long
Sacl As Long ' ACL
Dacl As Long ' ACL
End Type

' The two definitions for FORM_INFO_1 make the coding easier.
Public Type FORM_INFO_1
Flags As Long
pName As Long ' String
Size As SIZEL
ImageableArea As RECTL
End Type

Public Type sFORM_INFO_1
Flags As Long
pName As String
Size As SIZEL
ImageableArea As RECTL
End Type

Obj_GetFile 2009-09-10
  • 打赏
  • 举报
回复
1、你的纸张不是标准的纸张,打印机不一定支持。
2、需要知道打印机的无法打印区域,根据这个区域,确定页边距。
3、设置自定义纸张。
以下是MSDN的代码:

如何在 Windows NT 和 Windows 2000 中使用自定义页面大小打印
文章编号:282474
最后修改:2004年3月25日
修订:1.2
概要
在 Microsoft Windows 95、Windows 98 和 Windows Millennium Edition (Me) 系统上,可以灵活地自定义页面大小。但在运行 Windows NT 和 Windows 2000 的系统上,必须先将所有页面大小定义为页形 (form) 才能使用。本文介绍如何在 Windows NT 和 Windows 2000 上打印自定义页面大小,并包含一个代码示例,演示如何添加、选择和删除自定义页形。

Option Explicit

Private Sub Command1_Click()
Dim FormName As String

FormName = "MyCustomForm" ' Use special, user-defined form.
UseForm FormName
End Sub

Private Sub Command2_Click()
Dim FormName As String

' Get FormName from the ListBox.
On Error GoTo ListBoxERR ' Trap for no selection.
FormName = Mid(List1.Text, 1, InStr(1, List1.Text, " -") - 1)
On Error GoTo 0 ' Turn off Error trap.

UseForm FormName

Exit Sub
ListBoxERR:
MsgBox "Select a printer from the ListBox before using this option.", _
vbExclamation
End Sub

Private Sub Command3_Click()
Dim RetVal As Long
Dim PrinterHandle As Long ' Handle to printer
Dim PrinterName As String
Dim FormName As String
Dim Continue As Long

' Delete form that is selected in ListBox.
PrinterName = Printer.DeviceName ' Current printer
If OpenPrinter(PrinterName, PrinterHandle, 0&) Then

On Error GoTo ListBoxERR ' Trap for no selection.
FormName = Mid(List1.Text, 1, InStr(1, List1.Text, " -") - 1)
On Error GoTo 0 ' Turn off Error trap.

Continue = MsgBox("Are you sure you want to permanently remove " & _
FormName & " from " & PrinterName & "?", vbYesNo)
If Continue = vbYes Then
RetVal = DeleteForm(PrinterHandle, FormName & Chr(0))
If RetVal <> 0 Then ' DeleteForm succeeded.
List1.Clear ' Reflect the deletion in the ListBox.
Form_Load ' Rebuild the list.
MsgBox FormName & " deleted!", vbInformation, "Success!"
Else
MsgBox FormName & " not deleted!" & vbCrLf & vbCrLf & _
"Error code: " & Err.LastDllError, vbInformation, "Failure!"
End If
End If
ClosePrinter (PrinterHandle)
End If

Exit Sub
ListBoxERR:
MsgBox "Select a printer from the ListBox before using this option.", _
vbExclamation
ClosePrinter (PrinterHandle)
End Sub

Private Sub Form_Load()
Dim NumForms As Long, I As Long
Dim FI1 As FORM_INFO_1
Dim aFI1() As FORM_INFO_1 ' Working FI1 array
Dim Temp() As Byte ' Temp FI1 array
Dim BytesNeeded As Long
Dim PrinterName As String ' Current printer
Dim PrinterHandle As Long ' Handle to printer
Dim FormItem As String ' For ListBox
Dim RetVal As Long
Dim FormSize As SIZEL ' Size of desired form

PrinterName = Printer.DeviceName ' Current printer
If OpenPrinter(PrinterName, PrinterHandle, 0&) Then
With FormSize ' Desired page size
.cx = 214000
.cy = 216000
End With
ReDim aFI1(1)
RetVal = EnumForms(PrinterHandle, 1, aFI1(0), 0&, BytesNeeded, _
NumForms)
ReDim Temp(BytesNeeded)
ReDim aFI1(BytesNeeded / Len(FI1))
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)
' List name and size including the count (index).
FormItem = PtrCtoVbString(.pName) & " - " & .Size.cx / 1000 & _
" mm X " & .Size.cy / 1000 & " mm (" & I + 1 & ")"
List1.AddItem FormItem
End With
Next I
ClosePrinter (PrinterHandle)
End If
End Sub
msdtx 2009-09-10
  • 打赏
  • 举报
回复
用自定义纸张可能不管用,如果您的客户拿尺子量好纸张设置到系统中,但打印出来的结果还是不对,他是骂卖骚公司呢还是骂你呢?
页末用CurrentX,CurrentY 定位,PSet打一个定位点标记(好自己用尺子量),再EndDoc。
msdtx 2009-09-10
  • 打赏
  • 举报
回复
这个想法是好的,我试过在纸张的最下边打印一条横线,但这条横线打出来后距离纸张最下边有0.5厘米的距离,你说的校正值走一段空白距离如何实现呢?

打印机和窗体的打印定位方法都是一样的,用CurrentX,CurrentY定位啊。
另:执行 EndDoc 后打印机确实会按它自己的方式再走一段保留距离(不可打印的边界),但可以肯定同一打印机同一纸型其保留距离是一定值。
cqmi2009 2009-09-10
  • 打赏
  • 举报
回复
连打11页,然后测量首尾两页相同位置(文本行)之间的距离,除10就是打印机的走纸高度,与页面设置比较,进行调整。

按你说的做了,得出的走纸高度是8.9厘米。
页面设置如下:
宽度 24.1cm
高度 9.3cm
上下左右边距都是0cm

请问如何调整纸张?
Tiger_Zhao 2009-09-10
  • 打赏
  • 举报
回复
1)26楼说得不错,你用 1600K 的驱动试试。
2)不停调整页面设置的高度,用连打11页的方式测试实际走纸高度,使得逐渐接近到 9.3 厘米。
cqmi2009 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 36 楼 jjhhgg1111 的回复:]
引用 2 楼 mybelta2 的回复:
用程序不好,可以直接在控制面板的打印机设置里添加一个自定义纸张类型,不需要程序控制打印机走纸。


调整自定义纸张的大小应该可以
[/Quote]

理论上可行,实际操作过,完全不行,如果自定义的纸张高度大于实际纸张高度的话,进第一页纸还可以,后面就乱套了,一会走两页,一会走一页!
Tiger_Zhao 2009-09-10
  • 打赏
  • 举报
回复
微调不是常用功能,难道你换的4台针式打印都坏了?
如果再买一台新的打印机,新旧混用怎么办?
硬件不好就修一下。
布衣散人 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mybelta2 的回复:]
用程序不好,可以直接在控制面板的打印机设置里添加一个自定义纸张类型,不需要程序控制打印机走纸。
[/Quote]

调整自定义纸张的大小应该可以
zdingyun 2009-09-10
  • 打赏
  • 举报
回复
[Quote=引用 34 楼 cqmi2009 的回复:]
是的,现在用的是LQ1600的驱动,由于打印机比较老了,微调功能不大好使了。现在采取了每页EndDoc一下后再直接向LPT端口写个进纸5毫米的命令,问题基本解决了。

多谢各位热心的朋友!
[/Quote]
也只能是这么处理了.
cqmi2009 2009-09-10
  • 打赏
  • 举报
回复
是的,现在用的是LQ1600的驱动,由于打印机比较老了,微调功能不大好使了。现在采取了每页EndDoc一下后再直接向LPT端口写个进纸5毫米的命令,问题基本解决了。

多谢各位热心的朋友!
cqmi2009 2009-09-09
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 tiger_zhao 的回复:]
越说越离谱了。
开始还是0.5毫米,现在成了0.5厘米了。

任何计量工具都是有误差的,0.5毫米是肉眼估计的吧。
假定你的纸张尺寸是精确的,可能此类打印机走纸长度的测量有误差,
a)在打印机设置中纸张长度加长0.5毫米;
b)某些打印机上有微调按钮,手工调整一下。
[/Quote]

压根都没有出现过0.5毫米

每页少走0.5厘米,把纸张定义的高度增加0.5厘米后第一页刚好走完,打第二页时直接走两页纸!
king06 2009-09-09
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 tiger_zhao 的回复:]
[/Quote]
LZ的5毫米=0.5厘米
Tiger_Zhao 2009-09-09
  • 打赏
  • 举报
回复
越说越离谱了。
开始还是0.5毫米,现在成了0.5厘米了。

任何计量工具都是有误差的,0.5毫米是肉眼估计的吧。
假定你的纸张尺寸是精确的,可能此类打印机走纸长度的测量有误差,
a)在打印机设置中纸张长度加长0.5毫米;
b)某些打印机上有微调按钮,手工调整一下。
cqmi2009 2009-09-09
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 msdtx 的回复:]
给用户一个走纸修正的参数设置,通过这个校正值走一段空白距离。
不过这样做还不够,还需要一个输出点,我自己把它叫做定位点,让打印机打印出这个点。这仅是我的经验。
[/Quote]

这个想法是好的,我试过在纸张的最下边打印一条横线,但这条横线打出来后距离纸张最下边有0.5厘米的距离,你说的校正值走一段空白距离如何实现呢?
msdtx 2009-09-09
  • 打赏
  • 举报
回复
给用户一个走纸修正的参数设置,通过这个校正值走一段空白距离。
不过这样做还不够,还需要一个输出点,我自己把它叫做定位点,让打印机打印出这个点。这仅是我的经验。
加载更多回复(21)

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧