-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
60 lines (56 loc) · 2.23 KB
/
Program.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
57
58
59
60
using DevExpress.Office.Services;
using DevExpress.Security;
using DevExpress.XtraRichEdit;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
namespace RichIUriStreamProviderExample {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
private static string basePath = Directory.GetCurrentDirectory() + @"\TestDocs\";
static void Main(string[] args) {
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
// Custom IUriStreamProvider registration
IUriStreamService uriStreamService = wordProcessor.GetService<IUriStreamService>();
uriStreamService.RegisterProvider(new CustomUriStreamProvider(basePath, "bmp"));
wordProcessor.LoadDocument(basePath + "test.html");
wordProcessor.SaveDocument("Result.docx", DocumentFormat.OpenXml);
}
//Open the result
var p = new Process();
p.StartInfo = new ProcessStartInfo(@"Result.docx")
{
UseShellExecute = true
};
p.Start();
}
}
public class CustomUriStreamProvider : IUriStreamProvider
{
private string basePath;
private string imageExtension;
public string BasePath { get { return basePath; } set { basePath = value; } }
public string ImageExtension { get { return imageExtension; } set { imageExtension = value; } }
public CustomUriStreamProvider(string basePath, string imageExtension)
{
BasePath = basePath;
ImageExtension = imageExtension;
}
public Stream GetStream(string url)
{
string fileName = string.Format("{0}.{1}", url.Replace("cid:", string.Empty), ImageExtension);
MemoryStream memoryStream = new MemoryStream();
using (Image image = Image.FromFile(BasePath + fileName))
image.Save(memoryStream, ImageFormat.Bmp);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
}
}