views:

7

answers:

1
XpsDocument xpsDoc = new XpsDocument(fileName, FileAccess.Read);
documentViewer.Document = xpsDoc.GetFixedDocumentSequence();

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

Why?

A: 

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.

CSharpered