全部,
我有以下代码用于打印写入磁盘的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之间。由于某种原因,一些文件打印而其他文件没有打印。似乎文件大小和打印成功之间没有相关性。没有错误因为这是处理错误。
有没有人遇到这样的问题?如果您有任何问题,请与我们联系。
答案 0 :(得分:0)
我有一个类似的问题,我发现如果我增加睡眠时间,那么线程有时间完成它所做的事情,然后打印PDF。试着希望它有所帮助