|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
请问大家知道用API怎么设置打印机中的PDF打印机
我自己写了如下
Private 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 Long
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As Long
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
Private Declare Function EnumPorts Lib "winspool.drv" Alias "EnumPortsA" (ByVal pName As String, ByVal Level As Long, pPorts As Any, ByVal cbBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Private Declare Function ConfigurePort Lib "winspool.drv" Alias "ConfigurePortA" (ByVal pName As String, ByVal hwnd As Long, ByVal pPortName As String) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
Private Declare Function AddPrinter Lib "winspool.drv" Alias "AddPrinterA" (ByVal pName As String, ByVal Level As Long, pPrinter As Any) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
Private Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Private Sub Form_Load()
Dim ret As Long
ret = ConfigurePort(vbNullString, Me.hwnd, ByVal "c:\")
If ret = 0 Then
If Err.LastDllError = ERROR_CANCELLED Then
MsgBox "Der Dialog wurde abgebrochen.", vbInformation, "Dialog geschlossen"
Else
MsgBox "Der Port ist nicht verfügbar.", vbInformation, "Fehler " & Err.LastDllError
End If
End If
ret = InstallPrinter("Adobe PDF 2", "Adobe PDF Converter", "c:\1.pdf", , "Adobe")
MsgBox "OK"
End Sub
Function InstallPrinter(ByVal sPrinterName As String, ByVal sDriver As String, _
Optional ByVal sPort As String = "c:\1.pdf", Optional sServer As String, _
Optional sComment As String) As Boolean
Dim hPrinter As Long
Dim PI As PRINTER_INFO_2
' fill the PRINTER_INFO_2 struct
With PI
.pPrinterName = sPrinterName
.pDriverName = sDriver
.pPortName = sPort
.pServerName = sServer
.pComment = sComment
.pPrintProcessor = "WinPrint"
.Priority = 1
.DefaultPriority = 1
.pDatatype = "RAW"
End With
' add the printer
hPrinter = AddPrinter(sServer, 2, PI)
' if successful close the printer and return True
If hPrinter <> 0 Then
ClosePrinter hPrinter
InstallPrinter = True
End If
End Function
不过都无效,因为PDF打印机的属性拒绝修改, 如果把属性中的PORT给修改了, 就不用总是在打印前输入文件名了
用VB自动选择PDF打印倒是没问题, 关键不知如何用VB自动填写对话框
[ Last edited by Mephis on 2005-6-24 at 21:55 ] |
|