0
所有,不工作100%打印在vb.net一个PDF时
我有下面的代码,我使用打印写入到磁盘的PDF文件:
Public Function PrintPDF(ByVal PDFFile As String, ByVal Printer As String, ByVal Timeout As Integer) As Integer
log_error.sendEventLog("PrintPDF", "DEBUGGING - Printing PDF. File: " & PDFFile & ". Printer: " & Printer, EventLogEntryType.Information)
If Printer.Trim.Length = 0 Then
Printer = (New System.Drawing.Printing.PrinterSettings).PrinterName
End If
Dim Proc As New System.Diagnostics.Process
Try
Proc.EnableRaisingEvents = True
Proc.StartInfo.FileName = PDFFile
Proc.StartInfo.Arguments = Chr(34) + Printer + Chr(34)
Proc.StartInfo.Verb = "PrintTo"
Proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
Proc.StartInfo.CreateNoWindow = True
Proc.Start()
Catch ex As Exception
log_error.sendEventLog("PrintPDF Error", "An issue has occured when attemtping to print a PDF", EventLogEntryType.Error)
End Try
Do While Timeout > 0 AndAlso Not Proc.HasExited
System.Threading.Thread.Sleep(1000)
Timeout -= 1
Loop
If Not Proc.HasExited Then
log_error.sendEventLog("PrintPDF", "Process Killed", EventLogEntryType.Information)
Proc.Kill()
End If
log_error.sendEventLog("PrintPDF", "Process Closed", EventLogEntryType.Information)
Proc.Close()
Proc.Dispose()
Return 0
End Function
当利用这种方法,我循环了大约10个PDF文档。这些文件的范围在2mb到5mb之间。由于某种原因,某些文件可能会打印,而其他文件则不会。文件大小和打印成功之间似乎没有关联。在处理过程中不会出现任何错误。
有没有人遇到过像这样的问题?请让我知道,如果你有任何问题。