Question

I'm creating a custom report using WPF. I'm using DocumentViewer with FixedDocument, and all apparently works, the document I'm creating is visible on the screen and it works on the printer too. But if I try to print using the Microsoft XPS Document Writer virtual printer, and I open the created file with the XPS document receiver I receive the "The Page cannot be displayed" error: enter image description here

I did some rollback in the project history and apparently the error happens when the document pass from single page to multiple page. As another hint: the document contains images and fonts as embedded resource. No idea if this change the behavior or not.

EDIT I found the code causing the problem:

<Style TargetType="FixedPage">
                <Setter Property="Width" Value="1122.24"/>
                <Setter Property="Height" Value="793"/>
            </Style>

These are dimensions for an A4 in landscape. If I specify a size different from default, teh xps viever seems go crazy, any idea ?

Was it helpful?

Solution

I figured out myself. For some reasons I can't understand if I set the page size as a style form resources, it works on printer and on the DocumentViewer, but it fails when it exports the xps. To fix this I just specified the size in each page:

<FixedPage Height="816" Width="1056" >

It is a little silly because I know in advance how big each page is, so having a type based style seems a good idea to me, but it did not work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top