using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.Office.Interop.Word; using Word = Microsoft.Office.Interop.Word; using System.Windows.Xps.Packaging; //using System.IO; using System.Runtime.InteropServices; using Microsoft.Office.Core; namespace XPSViewer { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : System.Windows.Window { public MainWindow() { InitializeComponent(); } public string convertWordToXps(string path, string wordDocName) { Word.Application wordApp = new Word.Application(); string pathe = System.AppContext.BaseDirectory; wordApp.Documents.Open(string.Concat(path, "\\", wordDocName), ConfirmConversions: false, ReadOnly: true); string xpsFile = string.Concat(path, "\\", System.IO.Path.GetFileNameWithoutExtension(wordDocName), ".xps"); try { //wordApp.ActiveDocument.ExportAsFixedFormat(xpsFileName, WdExportFormat.wdExportFormatXPS, false, WdExportOptimizeFor.wdExportOptimizeForOnScreen, WdExportRange.wdExportAllDocument, 1, 1, WdExportItem.wdExportDocumentContent, false, true, WdExportCreateBookmarks.wdExportCreateNoBookmarks, false, true, false, nullObject); wordApp.ActiveDocument.SaveAs2(xpsFile, FileFormat: Word.WdSaveFormat.wdFormatXPS); return xpsFile; } catch (Exception e) { } finally { wordApp.Quit(SaveChanges: false, OriginalFormat: Type.Missing, RouteDocument: Type.Missing); } return null; } private void Button_Click(object sender, RoutedEventArgs e) { string path = System.AppContext.BaseDirectory; string fileName = "test.docx"; string xpsFile= convertWordToXps(path, fileName); XpsDocument doc = new XpsDocument(xpsFile, FileAccess.Read); xDocView.Document = doc.GetFixedDocumentSequence(); } } }