2,854 questions
You can use DocumentViewer to view control that can host paginated FixedDocument content such as an XpsDocument. I will show you a sample of using DocumentViewer to print pdf:
Here is the cs code:
public MainWindow()
{
InitializeComponent();
LoadDocumentViewer("E:\\WPF case\\0622\\pdf\\temp.xps", docViewer);
}
static XpsDocument xpsPackage = null;
public static void LoadDocumentViewer(string xpsFileName, DocumentViewer viewer)
{
XpsDocument oldXpsPackage = xpsPackage;
xpsPackage = new XpsDocument(xpsFileName, FileAccess.Read, CompressionOption.NotCompressed);
FixedDocumentSequence fixedDocumentSequence = xpsPackage.GetFixedDocumentSequence();
viewer.Document = fixedDocumentSequence as IDocumentPaginatorSource;
if (oldXpsPackage != null)
oldXpsPackage.Close();
xpsPackage.Close();
}
Add a DocumentViewer in the xaml:
<DocumentViewer Name="docViewer"></DocumentViewer>