I read data from printer like this:
using (Stream stream = client.GetStream())
{
using (MemoryStream ms = new MemoryStream())
{
stream.CopyTo(ms);
client.Close();
byte[] result = ms.ToArray();
...
using (var memoryStream = new MemoryStream(result))
{
using (var package = Package.Open(memoryStream, FileMode.Open))
{
var packageUri = new Uri("memorystream://printstream");
PackageStore.AddPackage(packageUri, package);
var xpsDocument = new XpsDocument(package, CompressionOption.Fast, packageUri.OriginalString);
return xpsDocument.GetFixedDocumentSequence() // NULL
I tried also saving stream directly to the file and then read as File.ReadAllBytes(filePath), but result is the same.
After I save stream to the file I can open it via XpsViewer without any problem.
Strange but it's working. I have to used XpsConverter.exe and convert .xps file to .xps. Here is @AXMIM solution