连续打印的问题

aixin0871 2010-03-19 11:32:38
连续纸打印时,每打印一次后会自动走纸A4纸的长度,若打印时是连续输出多次打印内容且每次打印的内容又较少,则会很浪费纸张,有什么办法可以实现打印机即打即停?可以在VB6.0里用代码实现吗?我们的打印机是LQ300+
...全文
802 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
qtcks 2011-02-13
  • 打赏
  • 举报
回复
留个记号,以后备查
HBJMSHOP 2011-02-10
  • 打赏
  • 举报
回复
不知这种打印速度如何
lihaorong 2010-05-11
  • 打赏
  • 举报
回复
22楼的可行,值得引用。谢谢。
  • 打赏
  • 举报
回复
留个记号,以后备查
aixin0871 2010-04-03
  • 打赏
  • 举报
回复
另提醒一下:设置新尺寸时不要采用打字机已有的尺寸 如210000*297000(210mm*297mm A4)
aixin0871 2010-04-03
  • 打赏
  • 举报
回复
谢谢大家,这个问题终于顺利解决,今日浏览留言 发现同21 22 楼的办法异曲同工。希望遇到此问题的同仁可以参考。
笨狗先飞 2010-03-30
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 aixin0871 的回复:]
先谢谢大家! 是不是我没有表达清楚? 我们开发的系统是用来做批发行业的,他们的销售单长度不一,要求连续打印,如果换页啦,打印机会走纸一个A4的幅高,可能有大量的空白 ,所以想让打印机在打印完内容后,能停下来,不走纸
[/Quote]
用八楼的方法可以的,我以前用epson 300K+就可以实现
jieweibin 2010-03-30
  • 打赏
  • 举报
回复
'接上页
Public Function SelectForm(FormName As String, ByVal MyhWnd As Long,PaperHeight 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 "维修测试单", 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 = "维修测试单" Then
' Use form "维修测试单", adding it if necessary.
' Set the desired size of the form needed.
With FormSize ' Given in thousandths of millimeters
.cx = 210000 ' width
.cy = PaperHeight ' 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, "维修测试单")
AddNewForm PrinterHandle, FormSize, "维修测试单"
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

'窗体代码
Private Sub Command1_Click()

Dim RetVal As Integer
Dim PHeight as long
Pheight=279000 '实际高度通过打印内容多少计算,具体代码自己调试
RetVal = SelectForm("维修测试单", Me.hwnd,Pheight) '每次实际高度在这里通过实参PHeight传入

Select Case RetVal

Case FORM_NOT_SELECTED ' 0
' Selection failed!
MsgBox "Unable to retrieve From name", vbExclamation, _
"Operation halted!"
Case FORM_SELECTED ' 1
'定位打印

Printer.ScaleMode = vbCentimeters '厘米
Printer.Font.Name = "宋体"
Printer.Font.Size = 12
Printer.CurrentX = 16.6
Printer.CurrentY = 1.9
Printer.Print "打印测试内容"
'........
Printer.EndDoc

End Select

End Sub
jieweibin 2010-03-30
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 sdfkfkd 的回复:]
引用 15 楼 aixin0871 的回复:

先谢谢大家! 是不是我没有表达清楚? 我们开发的系统是用来做批发行业的,他们的销售单长度不一,要求连续打印,如果换页啦,打印机会走纸一个A4的幅高,可能有大量的空白 ,所以想让打印机在打印完内容后,能停下来,不走纸

楼主可以设置一个自定义纸张,然后用这个自定义纸张打印
这样可以保证尽量少地浪费
[/Quote]

至于自定义纸张的高度可以通过打印的行数按一定比例换算成实际高度,调用时用参数形式传进即可,下面是搜集的代码

'模块
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

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

黄昏的投影 2010-03-30
  • 打赏
  • 举报
回复
代码我就不写了,给出我的两种思路:

(1)总体内容较少时,可以使用Print类。

(2)程序中,动态设置打印区域。
lovewangya 2010-03-26
  • 打赏
  • 举报
回复
咨询厂家
特别 2010-03-24
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 aixin0871 的回复:]

先谢谢大家! 是不是我没有表达清楚? 我们开发的系统是用来做批发行业的,他们的销售单长度不一,要求连续打印,如果换页啦,打印机会走纸一个A4的幅高,可能有大量的空白 ,所以想让打印机在打印完内容后,能停下来,不走纸
[/Quote]
楼主可以设置一个自定义纸张,然后用这个自定义纸张打印
这样可以保证尽量少地浪费
aixin0871 2010-03-24
  • 打赏
  • 举报
回复
热敏打印机 打印机不支持三联单呀 但这个客户原来用的软件是可以实现的 只是软件在其他方面不如意才换的
孤独剑_LPZ 2010-03-24
  • 打赏
  • 举报
回复
看lz的业务,不如改用热敏打印机吧,可以连续打印
aixin0871 2010-03-24
  • 打赏
  • 举报
回复
先谢谢大家! 是不是我没有表达清楚? 我们开发的系统是用来做批发行业的,他们的销售单长度不一,要求连续打印,如果换页啦,打印机会走纸一个A4的幅高,可能有大量的空白 ,所以想让打印机在打印完内容后,能停下来,不走纸
ChinaITOldMan 2010-03-23
  • 打赏
  • 举报
回复
learning
苍狼传说 2010-03-22
  • 打赏
  • 举报
回复
你要的功能可以说绝对可以办到!打印机都支持使用Esc码来控制的命令,每种打印机都差不多,但可能控制码稍有区别,但具体还是要以打印机说明书中的为准。

既然不好实现,查找打印机命令也麻烦,何不换个思路呢:
将要打印的东西调整到刚够一页的时候再打印,不就刚好满足你的要求了么?
王二.麻子 2010-03-22
  • 打赏
  • 举报
回复
printer.ScaleHeight
printer.ScaleWidth

printer.TextHeight
printer.TextWidth
王二.麻子 2010-03-22
  • 打赏
  • 举报
回复
以前用程序在A4上打,在printer对象上,可以获取1页纸张的大小.然后设置打印字体,行距等,打印..

不知道对连续打印纸是否有效果...
东方之珠 2010-03-20
  • 打赏
  • 举报
回复
打印机一般都是按页打印,即使只有一行文字,A4复印纸也会走一页,这是在Office里面的情况。
如果自己编程控制打印机,使用所见即所得的报表控件,也是如此。
除非你自己编程控制打印机,打印一行文字后马上让打印机停止,打印机能不能听你的话就不知道了。
加载更多回复(9)

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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