打印为PDF-如何避免自动显示屏幕以请求保存位置?
我正在开发一个遗留应用程序,并试图让VB6将打印输出发送到pdf打印机(Nitro)。应用程序的输出应最终打印到特定位置/文件名的pdf文件中 问题: 当我调用任何打印为PDF-如何避免自动显示屏幕以请求保存位置?,pdf,printing,vb6,Pdf,Printing,Vb6,我正在开发一个遗留应用程序,并试图让VB6将打印输出发送到pdf打印机(Nitro)。应用程序的输出应最终打印到特定位置/文件名的pdf文件中 问题: 当我调用任何打印机函数时,它会弹出一个对话框,但我看不到设置对话框默认路径和文件名的方法。有办法做到这一点吗 即使我创建了自己的对话框,只要对Printer进行任何函数调用,它都会弹出一个对话框 弹出对话框的代码行: 'How do I set the dialogue box it opens here to a default filenam
打印机
函数时,它会弹出一个对话框,但我看不到设置对话框默认路径和文件名的方法。有办法做到这一点吗
即使我创建了自己的对话框,只要对Printer
进行任何函数调用,它都会弹出一个对话框
弹出对话框的代码行:
'How do I set the dialogue box it opens here to a default filename/location?
Printer.PaintPicture .Picture, .Left + lngAddToLeft, .Top + lngAddToTop, .Width, .Height
首先,必须将系统的默认打印机设置为“Nitro的打印机名称” 下面的代码可以帮助你做到这一点
Private Sub set_Nitro_As_Default()
Dim prn As Printer
If Printers.Count > 0 Then
For Each prn In Printers
If prn.DeviceName = [Nitro Printer Name] Then 'printer that u want to use
Set Printer = prn
Exit For
End If
Next prn
End If
End Sub
要打印某些文本、标签或图形对象,必须向项目中添加picturebox。它包含所有要打印的对象
在准备好所有对象(如标签或形状)以及所有要打印的对象后,请调用此sub将picturebox图像保存在临时bmp文件中
'add this declaration on top of your project
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20& ' Draw all owned windows
'this function save PicBox image in FileName path
'PicBox Contain All thing which you want to print
Public Sub SavePictureBox(PicBox As PictureBox, FileName As String)
Dim rv As Long
Dim ar As Boolean
With PicBox
'Save ReDraw value
ar = .AutoRedraw
.AutoRedraw = True
'Draw controls to picture box
rv = SendMessage(.hwnd, WM_PAINT, .hdc, 0)
rv = SendMessage(.hwnd, WM_PRINT, .hdc, _
PRF_CHILDREN Or PRF_CLIENT Or PRF_OWNED)
'save picture box
SavePicture .Image, FileName
.Cls
'Restore ReDraw
.AutoRedraw = ar
End With
End Sub
您必须在主打印命令中添加类似的内容
private sub iPrint()
'firstly set your intended printer as default
call set_Nitro_As_Default
'set some Generic setting
Printer.PrintQuality = vbPRPQHigh
Printer.PaperSize = vbPRPSA4
for i=1 to [your intended page count]
'do some thing for Arrange your labels and objects to make it ready to print
'after prepare your all thing on picturebox
call SavePictureBox([printed PictureBox], App.path & "\tmp.bmp")
'print this page
'note that you can set margin and your printed page size
Printer.PaintPicture LoadPicture(App.Path & "\tmp.bmp"), 0, 0, _
LoadPicture(App.Path & "\tmp.bmp").Width, _
LoadPicture(App.Path & "\tmp.bmp").Height, _
0, 0, _
Printer.Width, _
Printer.Height
Printer.NewPage
next i
Printer.EndDoc
end sub
它已完成您可以这样做,因此无法使用内置的打印机
对象。