Hi,
Due to security patch update dated 13 dec 2022 on machine, XPS document is unable display on DocumentViewer UI control.Although microsoft provided an workaround regarding this. But can any one please help me out is there any other control availabe in WPF that can dispaly the XPS document.
Please let me know
Thanks

Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 2, 2023, 1:33 AM EST
Hello Saumya,
You can use the "FlowDocumentReader" control to display an XPS document in WPF.
You can get more details here: https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.flowdocumentreader?view=windowsdesktop-7.0
Thanks
Naimish
David Brown28 reputationPosted Jul 11, 2023, 10:20 AM EDT
Consider using a FixedDocument control: Create a FixedDocument object and add the XPS document to it, then set it as content into a DocumentPanel control or other container.
XpsDocument xpsDocument = new XpsDocument("..\\..\\Sample.xps", FileAccess.Read); FixedDocumentSequence fixedDocumentSequence = xpsDocument.GetFixedDocumentSequence(); FixedDocument fixedDocument = fixedDocumentSequence.References[0].GetDocument(false); DocumentPanel documentPanel = new DocumentPanel(); documentPanel.Children.Add(fixedDocument.DocumentPaginator.GetPage(0).Visual);Praveen Mishra183 reputationPosted Jul 13, 2023, 4:57 AM EDT
Hi David ,
Add a reference to the
WindowsBaseandPresentationCoreassemblies in your project. These assemblies are required to work with XPS documents.In your XAML file, add the
DocumentViewercontrol to your UI layout.In your C# code, you need to load and display the XPS document using the
DocumentViewerusing System.Windows; using System.Windows.Controls; using System.Windows.Xps.Packaging; namespace YourNamespace { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); LoadXpsDocument(); } private void LoadXpsDocument() { // Replace "path_to_your_xps_file.xps" with the actual path to your XPS document. string xpsFilePath = "path_to_your_xps_file.xps"; try { XpsDocument xpsDocument = new XpsDocument(xpsFilePath, System.IO.FileAccess.Read); documentViewer.Document = xpsDocument.GetFixedDocumentSequence(); } catch (System.IO.FileNotFoundException) { MessageBox.Show("The specified XPS document file was not found."); } catch (System.IO.FileFormatException) { MessageBox.Show("The specified file is not a valid XPS document."); } } } }In the
LoadXpsDocument()method, you create an instance of theXpsDocumentclass by providing the path to your XPS document file. Then, you set theDocumentproperty of theDocumentViewercontrol to theFixedDocumentSequenceobtained from theXpsDocument.Make sure to replace
"path_to_your_xps_file.xps"with the actual path to your XPS document.That's it! When you run your application, it should load and display the XPS document in the
DocumentViewercontrol.Marvin ReidRank #1,963 · 746 reputationPosted Jul 19, 2023, 11:26 AM EDT
You can load that XPS file using the WPF DocumentViewer provided through the LEADTOOLS SDK. Here is some sample code that highlights the tutorial:
private ObjectCache cache; private DocumentViewer docViewer; void InitDocumentViewer() { var createOptions = new DocumentViewerCreateOptions { ViewContainer = _centerGrid, ThumbnailsContainer = _thumbnailsTabPageGrid, UseAnnotations = false }; docViewer = DocumentViewerFactory.CreateDocumentViewer(createOptions); docViewer.View.ImageViewer.Zoom(ControlSizeMode.FitAlways, 1, docViewer.View.ImageViewer.DefaultZoomOrigin); cache = new FileCache { CacheDirectory = Path.GetFullPath(@".\CacheDir"), }; }https://www.leadtools.com/help/sdk/tutorials/dotnet-wpf-display-files-in-the-document-viewer.html