-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathImageHelper.cs
65 lines (58 loc) · 2.56 KB
/
ImageHelper.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
61
62
63
64
65
using iDiTect.Word.Editing;
using iDiTect.Word.IO;
using iDiTect.Word.Shapes;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace iDiTect.Word.Demo
{
public static class ImageHelper
{
public static void AddInlineImage()
{
WordDocument document = new WordDocument();
WordDocumentBuilder builder = new WordDocumentBuilder(document);
//Add in-line image using builder
builder.InsertText("Simple sentence 1 in line. ");
using (Stream stream = File.OpenRead("sample.jpg"))
{
builder.InsertImageInline(stream, "jpg");
}
builder.InsertText("Simple sentence 2 in line");
//Add in-line image using Paragraph object
Paragraph paragraph = builder.InsertParagraph();
//Add text before
TextInline textStart = paragraph.Inlines.AddText();
textStart.Text = "Text add using paragraph start.";
//Insert image in the middle of text content
ImageInline imageInline = paragraph.Inlines.AddImageInline();
using (Stream stream = File.OpenRead("sample.png"))
{
imageInline.Image.ImageSource = new Basic.Media.ImageSource(stream, "png");
}
//Add text after
TextInline textEnd = paragraph.Inlines.AddText();
textEnd.Text = "Text add using paragraph end.";
WordFile wordFile = new WordFile();
File.WriteAllBytes("AddImageInline.docx", wordFile.Export(document));
}
public static void AddFloatingImage()
{
WordDocument document = new WordDocument();
WordDocumentBuilder builder = new WordDocumentBuilder(document);
builder.CharacterState.FontSize = 24;
//Add floating image using builder
using (Stream stream = File.OpenRead("sample.jpg"))
{
FloatingImage floatingImage1 = builder.InsertFloatingImage(stream, "jpg");
floatingImage1.Wrapping.WrappingType = ShapeWrappingType.Square;
}
builder.InsertText("This text sentence content will display at the square of the floating image. ");
builder.InsertText("This text sentence content will display at the square of the floating image.");
WordFile wordFile = new WordFile();
File.WriteAllBytes("AddFloatingImage.docx", wordFile.Export(document));
}
}
}