-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.vb
76 lines (67 loc) · 2.57 KB
/
Program.vb
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
Imports DevExpress.Office.Services
Imports DevExpress.Security
Imports DevExpress.XtraRichEdit
Imports System
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Windows.Forms
Namespace RichIUriStreamProviderExample
Module Program
''' <summary>
''' The main entry point for the application.
''' </summary>
Private basePath As String = Directory.GetCurrentDirectory() & "\TestDocs\"
Sub Main(args As String())
Using wordProcessor As New RichEditDocumentServer()
' Custom IUriStreamProvider registration
Dim uriStreamService As IUriStreamService = wordProcessor.GetService(Of IUriStreamService)()
uriStreamService.RegisterProvider(New CustomUriStreamProvider(basePath, "bmp"))
wordProcessor.LoadDocument(basePath & "test.html")
wordProcessor.SaveDocument("Result.docx", DocumentFormat.OpenXml)
End Using
' Open the result
Dim p As New Process()
p.StartInfo = New ProcessStartInfo("Result.docx") With {
.UseShellExecute = True
}
p.Start()
End Sub
End Module
Public Class CustomUriStreamProvider
Implements IUriStreamProvider
Private _basePath As String
Private _imageExtension As String
Public Property BasePath As String
Get
Return _basePath
End Get
Set(value As String)
_basePath = value
End Set
End Property
Public Property ImageExtension As String
Get
Return _imageExtension
End Get
Set(value As String)
_imageExtension = value
End Set
End Property
Public Sub New(basePath As String, imageExtension As String)
Me.BasePath = basePath
Me.ImageExtension = imageExtension
End Sub
Public Function GetStream(url As String) As Stream Implements IUriStreamProvider.GetStream
Dim fileName As String = String.Format("{0}.{1}", url.Replace("cid:", String.Empty), ImageExtension)
Dim memoryStream As New MemoryStream()
Using image As Image = Image.FromFile(BasePath & fileName)
image.Save(memoryStream, ImageFormat.Bmp)
End Using
memoryStream.Seek(0, SeekOrigin.Begin)
Return memoryStream
End Function
End Class
End Namespace