/
InlinePictureActions.cs
60 lines (56 loc) · 2.35 KB
/
InlinePictureActions.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit;
namespace RichEditDocumentServerAPIExample.CodeExamples
{
class InlinePicturesActions
{
static void ImageFromFile(RichEditDocumentServer wordProcessor)
{
#region #ImageFromFile
Document document = wordProcessor.Document;
DocumentPosition pos = document.Range.Start;
document.Images.Insert(pos, DocumentImageSource.FromFile("Documents\\beverages.png"));
#endregion #ImageFromFile
}
static void ImageCollection(RichEditDocumentServer wordProcessor)
{
#region #ImageCollection
Document document = wordProcessor.Document;
document.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);
ReadOnlyDocumentImageCollection images = document.Images;
// If the width of an image exceeds 50 millimeters,
// the image is scaled proportionally to half its size.
for (int i = 0; i < images.Count; i++)
{
if (images[i].Size.Width > DevExpress.Office.Utils.Units.MillimetersToDocumentsF(50))
{
images[i].ScaleX /= 2;
images[i].ScaleY /= 2;
}
}
#endregion #ImageCollection
}
static void SaveImageToFile(RichEditDocumentServer wordProcessor)
{
#region #SaveImageToFile
Document document = wordProcessor.Document;
document.LoadDocument("Documents\\MovieRentals.docx", DocumentFormat.OpenXml);
DocumentRange myRange = document.CreateRange(0, 100);
ReadOnlyDocumentImageCollection images = document.Images.Get(myRange);
if (images.Count > 0)
{
DevExpress.Office.Utils.OfficeImage myImage = images[0].Image;
System.Drawing.Image image = myImage.NativeImage;
string imageName = String.Format("Image_at_pos_{0}.png", images[0].Range.Start.ToInt());
image.Save(imageName);
System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName);
}
#endregion #SaveImageToFile
}
}
}