-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExportActions.vb
More file actions
145 lines (127 loc) · 8.08 KB
/
ExportActions.vb
File metadata and controls
145 lines (127 loc) · 8.08 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports DevExpress.XtraRichEdit
Imports System.Diagnostics
Imports DevExpress.XtraPrinting
Imports System.IO
Imports DevExpress.XtraRichEdit.Export
Imports DevExpress.XtraRichEdit.API.Native
Imports Document = DevExpress.XtraRichEdit.API.Native.Document
Namespace RichEditDocumentServerAPIExample.CodeExamples
Friend Class ExportActions
Public Shared ExportRangeToHtmlAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.ExportActions.ExportRangeToHtml
Public Shared ExportRangeToPlainTextAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.ExportActions.ExportRangeToPlainText
Public Shared ExportToPDFAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.ExportActions.ExportToPDF
Public Shared ConvertHTMLtoPDFAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.ExportActions.ConvertHTMLtoPDF
Public Shared ConvertHTMLtoDOCXAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.ExportActions.ConvertHTMLtoDOCX
Public Shared ExportToHTMLAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.ExportActions.ExportToHTML
Public Shared BeforeExportAction As System.Action(Of DevExpress.XtraRichEdit.RichEditDocumentServer) = AddressOf RichEditDocumentServerAPIExample.CodeExamples.ExportActions.BeforeExport
Private Shared Sub ExportRangeToHtml(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#ExportRangeToHtml"
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx", DocumentFormat.OpenXml)
' Access a document.
Dim document As Document = wordProcessor.Document
If document.Paragraphs.Count > 2 Then
' Access the range of the first three paragraphs.
Dim range As DocumentRange = document.CreateRange(document.Paragraphs(CInt((0))).Range.Start, document.Paragraphs(2).Range.End.ToInt() - document.Paragraphs(0).Range.Start.ToInt())
' Save text contained in the target range in HTML format.
Dim htmlText As String = document.GetHtmlText(range, Nothing)
System.IO.File.WriteAllText("test.html", htmlText)
' Show the result in a browser window.
System.Diagnostics.Process.Start("test.html")
End If
#End Region ' #ExportRangeToHtml
End Sub
Private Shared Sub ExportRangeToPlainText(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#ExportRangeToPlainText"
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Access a document.
Dim document As DevExpress.XtraRichEdit.API.Native.Document = wordProcessor.Document
If document.Paragraphs.Count > 2 Then
' Obtain the plain text contained in the third paragraph.
Dim plainText As String = document.GetText(document.Paragraphs(CInt((2))).Range)
' Show the result in a dialog box.
System.Windows.Forms.MessageBox.Show(plainText)
End If
#End Region ' #ExportRangeToPlainText
End Sub
Private Shared Sub ExportToPDF(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#ExportToPDF"
' Load a document from a file.
wordProcessor.LoadDocument("Documents\MovieRentals.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Specify PDF export options.
Dim options As DevExpress.XtraPrinting.PdfExportOptions = New DevExpress.XtraPrinting.PdfExportOptions()
options.DocumentOptions.Author = "Mark Jones"
options.Compressed = False
options.ImageQuality = DevExpress.XtraPrinting.PdfJpegImageQuality.Highest
' Export the document to a stream in PDF format.
Using pdfFileStream As System.IO.FileStream = New System.IO.FileStream("Document_PDF.pdf", System.IO.FileMode.Create)
wordProcessor.ExportToPdf(pdfFileStream, options)
End Using
' Show the resulting PDF file.
System.Diagnostics.Process.Start("Document_PDF.pdf")
#End Region ' #ExportToPDF
End Sub
Private Shared Sub ConvertHTMLtoPDF(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#ConvertHTMLtoPDF"
' Load a document from an HTML file.
wordProcessor.LoadDocument("Documents\TextWithImages.htm")
' Save the document as a PDF file.
wordProcessor.ExportToPdf("Document_PDF.pdf")
' Show the resulting PDF file.
System.Diagnostics.Process.Start("Document_PDF.pdf")
#End Region ' #ConvertHTMLtoPDF
End Sub
Private Shared Sub ConvertHTMLtoDOCX(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#ConvertHTMLtoDOCX"
' Load a document from an HTML file.
wordProcessor.LoadDocument("Documents\TextWithImages.htm")
' Save the document as a DOCX file.
wordProcessor.SaveDocument("Document_DOCX.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Show the resulting DOCX file.
System.Diagnostics.Process.Start("Document_DOCX.docx")
#End Region ' #ConvertHTMLtoDOCX
End Sub
Private Shared Sub ExportToHTML(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#ExportDocumentToHTML"
' Load a document from a file.
wordProcessor.LoadDocument("Documents\MovieRentals.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Specify the path to the resulting HTML file.
Dim filePath As String = "Document_HTML.html"
' Save the document as an HTML file.
Using htmlFileStream As System.IO.FileStream = New System.IO.FileStream(filePath, System.IO.FileMode.Create)
wordProcessor.SaveDocument(htmlFileStream, DevExpress.XtraRichEdit.DocumentFormat.Html)
End Using
' Show the resulting HTML file.
System.Diagnostics.Process.Start(filePath)
#End Region ' #ExportDocumentToHTML
End Sub
Private Shared Sub BeforeExport(ByVal wordProcessor As DevExpress.XtraRichEdit.RichEditDocumentServer)
#Region "#HandleBeforeExportEvent"
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx")
' Handle the Before Export event.
AddHandler wordProcessor.BeforeExport,
Sub(s, e)
' Specify the export options before a document is exported to HTML.
Dim options As HtmlDocumentExporterOptions = TryCast(e.Options, HtmlDocumentExporterOptions)
If options IsNot Nothing Then
options.CssPropertiesExportType = Html.CssPropertiesExportType.Link
options.HtmlNumberingListExportFormat = Html.HtmlNumberingListExportFormat.HtmlFormat
options.TargetUri = "Document_HTML.html"
End If
End Sub
'RichEditDocumentServerAPIExample.CodeExamples.ExportActions.BeforeExportHelper.BeforeExport
' Save the document as an HTML file.
wordProcessor.SaveDocument("Document_HTML.html", DevExpress.XtraRichEdit.DocumentFormat.Html)
' Show the resulting HTML file.
System.Diagnostics.Process.Start("Document_HTML.html")
#End Region ' #HandleBeforeExportEvent
End Sub
End Class
End Namespace