-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentWindow.xaml.cs
56 lines (47 loc) · 1.74 KB
/
DocumentWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Aspose.Words;
using Aspose.Words.Saving;
using System;
using System.IO;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Xps.Packaging;
namespace StructGen
{
/// <summary>
/// Interaction logic for DocumentWindow.xaml
/// </summary>
public partial class DocumentWindow : Window
{
public DocumentWindow()
{
InitializeComponent();
}
public void UpdateDocumentContent(string filepath)
{
try
{
// Load the DOCX document
Document doc = new Document(filepath);
// Create an XpsSaveOptions object
XpsSaveOptions saveOptions = new XpsSaveOptions();
// Set the output XPS file path
string xpsFilePath = filepath + ".xps";
// Save the document as XPS
doc.Save(xpsFilePath, saveOptions);
// Load the XPS document
XpsDocument xpsDocument = new XpsDocument(xpsFilePath, FileAccess.Read);
// Get the FixedDocumentSequence from the XPS document
FixedDocumentSequence fixedDocumentSequence = xpsDocument.GetFixedDocumentSequence();
// Set the FixedDocumentSequence as the DocumentViewer's Document
documentViewer.Document = fixedDocumentSequence;
// Delete the temporary XPS file
File.Delete(xpsFilePath);
}
catch (Exception ex)
{
// Handle any exceptions that may occur during loading
MessageBox.Show($"Error loading XPS document: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}