Printing to Network Printer in Windows 8.1

  • Thread starter Thread starter davebis
  • Start date Start date
D

davebis

Guest
I have an issue printing in Windows 8.1. I have not seen this problem using Windows 7. Issue is that if the output is fairly large (> 50 pages), sometimes printing will stop midway through and the last page printed will just show:

ERROR: syntaxerror

OFFENDING COMMAND: < a bunch of random characters >

My thought is that the code is fine, but that the printed output is getting corrupted somehow in the print queue. The output does not always stop at the same page. I have shown that this happens on multiple printers (HP, Xerox). My code to handle the print is shown below. Targeting .NET Framework 4.0.

Just wondering if anyone else has experienced a similar problem.


Public Sub PrintToNamedPrinter(ByVal sPrinterName As String)
Try
Dim myLocalPrintServer As LocalPrintServer used to get the print queue
Dim myNetworkPrintServer As PrintServer used to get the print queue from a network printer
Dim q As System.Printing.PrintQueue = Nothing represents the print queue
Dim writer As System.Windows.Xps.XpsDocumentWriter used to write the xps document to the printer
Dim pt As New System.Printing.PrintTicket print ticket is used to help write data to the printer
Dim sPrinterServerName As String = "" the name of print server

need to either get the print queue from a network or local print server
If (InStr(sPrinterName, "\\") > 0) Then
network printer - get the printer name
sPrinterServerName = Left(sPrinterName, sPrinterName.LastIndexOf("\"))
define the print server from which the queue is to be retrieved
myNetworkPrintServer = New PrintServer(sPrinterServerName)
retrieve the print queue
q = myNetworkPrintServer.GetPrintQueue(sPrinterName)
Else
local printer
myLocalPrintServer = New LocalPrintServer
retrieve the print queue
q = myLocalPrintServer.GetPrintQueue(sPrinterName)
End If

If (Not q Is Nothing) Then
create the xps document writer
writer = PrintQueue.CreateXpsDocumentWriter(q)

set orientation to landscape
pt.PageOrientation = System.Printing.PageOrientation.Landscape
pt.PageMediaSize = New PageMediaSize(11 * 96, 8.5 * 96)

write the document to the printer
writer.Write(myFixedDoc.DocumentPaginator, pt)
writer = Nothing
End If

Catch ex As Exception
Throw New Exception(System.Reflection.MethodInfo.GetCurrentMethod.DeclaringType.Name & "." & _
System.Reflection.MethodInfo.GetCurrentMethod.Name & "->" & ex.Message, ex)
End Try
End Sub

Continue reading...
 
Back
Top