I have an xps file. When I try to print this file directly, I can do it without any error with my below code:
Dim defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue
Dim xpsPrintJob As PrintSystemJobInfo = defaultPrintQueue.AddJob("test", "C:\Temp\test.xps", False)
However, If I get this file from a web service as a byte array and save it as an xps file I cannot print it.
My save byte array codes are below:
FS = New IO.FileStream("C:\Temp\test.xps", FileMode.Create)
FS.Write(arrayByte, 0, arrayByte.Length)
FS.Close()
or this code:
File.WriteAllBytes("c:\Temp\test.xps", arrayByte)
When I try to print test.xps, I'm getting the error:
An unhandled exception of type 'System.Printing.PrintJobException' occurred in System.Printing.dll
Additional information: An exception occurred while creating print job information. Check inner exception for details.
Have can I handle this problem? Is anyone has any idea?
By the way, there is no need a web service. Please see my below code. You can try this any xps file. Firstly, I'm assinging the file as byte array Then, I'm saving the byte array as an xps file.
First XPS file is working but second one isn't working
Dim FS As FileStream
FS = File.Open("C:\Temp\test2.xps", FileMode.Open, FileAccess.Read)
Dim bByte(FS.Length) As Byte
FS.Read(bByte, 0, FS.Length)
FS.Close()
File.WriteAllBytes("c:\Temp\test2byte.xps", bByte)
Dim defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue
'This is working
Dim xpsPrintJob1 As PrintSystemJobInfo = defaultPrintQueue.AddJob("Test", "C:\Temp\test2.xps", False)
'This is not working
Dim xpsPrintJob2 As PrintSystemJobInfo = defaultPrintQueue.AddJob("Test", "C:\Temp\test2byte.xps", False)