Viewing Xps document - Compressed part has inconsistent data length

1k Views Asked by At
XpsDocument xpsDoc = new XpsDocument(fileName, FileAccess.Read);
documentViewer.Document = xpsDoc.GetFixedDocumentSequence();

Second line gives next error: Compressed part has inconsistent data length

Why?

1

There are 1 best solutions below

0
On

Ok, I've found an answer.

I have created Xps document in this way:

Package package = Package.Open(fileName, FileMode.Create);
XpsDocument xpsDocument = new XpsDocument(package);

Thus, after saving it and trying to view I got Compressed part has inconsistent data length error.

Then I changed

Package package = Package.Open(fileName, FileMode.Create);
XpsDocument xpsDocument = new XpsDocument(package);

to

XpsDocument xpsDocument = new XpsDocument(fileName, FileAccess.ReadWrite);

And it started working.

Hope this will help somebody who may face with it.