-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (49 loc) · 2.42 KB
/
Program.cs
File metadata and controls
55 lines (49 loc) · 2.42 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
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
namespace InlinePictures
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
wordProcessor.LoadDocument("Texts\\InlinePictures.rtf", DocumentFormat.Rtf);
Document document = wordProcessor.Document;
// Insert an image from a file.
DocumentRange rangeFound = document.FindAll("Visual Studio Magazine", SearchOptions.CaseSensitive)[0];
DocumentPosition pos = document.Paragraphs[document.Paragraphs.Get(rangeFound.End).Index + 2].Range.Start;
Shape imageFromFile = document.Shapes.InsertPicture(pos, DocumentImageSource.FromFile("Pictures\\ReadersChoice.png"));
imageFromFile.TextWrapping = TextWrappingType.InLineWithText;
// Insert an image from a stream.
pos = document.Paragraphs[4].Range.Start;
string imageToInsert = "information.png";
Assembly a = Assembly.GetExecutingAssembly();
Stream imageStream = a.GetManifestResourceStream("Resources." + imageToInsert);
Shape imageFromStream = document.Shapes.InsertPicture(pos, DocumentImageSource.FromStream(imageStream));
imageFromStream.TextWrapping = TextWrappingType.InLineWithText;
// Insert an image using its URI.
string imageUri = "http://i.gyazo.com/798a2ed48a3535c6c8add0ea7a4fc4e6.png";
SubDocument docHeader = document.Sections[0].BeginUpdateHeader();
Shape headerImage = docHeader.Shapes.InsertPicture(docHeader.Range.End, DocumentImageSource.FromUri(imageUri, wordProcessor));
headerImage.TextWrapping = TextWrappingType.InLineWithText;
// Save the resulting document.
wordProcessor.SaveDocument("InlinePictures.docx", DocumentFormat.OpenXml);
}
var p = new Process();
p.StartInfo = new ProcessStartInfo(@"InlinePictures.docx")
{
UseShellExecute = true
};
p.Start();
}
}
}