【问题标题】:How can I know the SPL file is completely written inside?我怎么知道 SPL 文件是完全写在里面的?
【发布时间】:2016-02-01 09:23:10
【问题描述】:

我想获取我的打印机当前的打印作业信息,所以我转到文件夹C:\Windows\System32\spool\PRINTERS并使用以下代码获取假脱机文件信息,

Public WithEvents _universalPrinterMonitor As PrinterQueueWatch.PrinterMonitorComponent

Private Sub UniversalPrinterMonitor_JobAdded(ByVal sender As Object, ByVal args As PrinterQueueWatch.PrintJobEventArgs) Handles _universalPrinterMonitor.JobAdded
    Try
        Dim fs As IO.FileStream
        If File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL") Then
            fs = New IO.FileStream(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL", _
                                   IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL")
        ElseIf File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL") Then
            fs = New IO.FileStream(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL", _
                                   IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL")
        Else
            args.PrintJob.Delete()
            MessageBox.Show("There was an error occured while executing your print job, please contact your system administrator for assistance.", _
                            "Spool File Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Throw New Exception("Spool File Not Found. System Path: " & Environment.GetFolderPath(Environment.SpecialFolder.System) & ". Spool File Id: " & _
                                args.PrintJob.JobId.ToString("D5") & ".SPL")
        End If

        Using fs
            'Thread.Sleep(1000)
            Dim sr As New IO.StreamReader(fs)
            Dim buffer As String
            Dim isEOF As Boolean = False
            Dim isColor As Boolean = False

            While Not isEOF
                buffer = sr.ReadLine
                If buffer Is Nothing Then
                    isEOF = True
                    Exit While
                End If

                If buffer.Contains("RENDERMODE=COLOR") Then
                    isColor = True
                    isEOF = True
                    Exit While
                End If
            End While

但是,有时我可以正确获取打印作业的颜色类型,有时却不能,因为buffer = sr.ReadLine 返回了 NULL 对象,并且我假设我的程序没有完全读取假脱机文件。

此外,我尝试了PrintQueueWatchargs.PrintJob.Color,但无论我将文档颜色类型更改为“B&W”还是“Color”,它总是返回“true”

在读取假脱机文件或使用 PrintQueueWatch 时我还需要注意什么?先谢谢了~!

【问题讨论】:

    标签: .net printing printqueuewatch


    【解决方案1】:

    您需要监控 JobWritten 事件(而不是 JobAdded),并且只有在触发该事件并且 PrintJob.Spooling = false 时才开始读取假脱机文件

    【讨论】:

      猜你喜欢
      • 2017-01-31
      • 1970-01-01
      • 2015-06-04
      • 1970-01-01
      • 2012-12-10
      • 2016-09-29
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      相关资源
      最近更新 更多