-
Notifications
You must be signed in to change notification settings - Fork 3
/
BookmarkHelper.cs
62 lines (52 loc) · 2.08 KB
/
BookmarkHelper.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
using iDiTect.Word.Editing;
using iDiTect.Word.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace iDiTect.Word.Demo
{
public static class BookmarkHelper
{
public static void AddBookmark()
{
WordDocument document = new WordDocument();
WordDocumentBuilder builder = new WordDocumentBuilder(document);
builder.InsertLine("First paragraph in this document.");
//Insert some content before bookmark
builder.InsertText("Second paragraph start. ");
//Select the content you want to bookmark
TextInline textBookmark = builder.InsertText("This is bookmark. ");
//Insert some content after bookmark
builder.InsertText("Second paragraph end.");
//Add bookmark with selected content
builder.InsertBookmark("bookmark1", textBookmark, textBookmark);
WordFile wordFile = new WordFile();
using (var stream = File.OpenWrite("AddBookmark.docx"))
{
wordFile.Export(document, stream);
}
}
public static void AddBookmark2()
{
WordDocument document = new WordDocument();
//Insert some content before bookmark
Section section = document.Sections.AddSection();
Paragraph para = section.Blocks.AddParagraph();
para.Inlines.AddText("Sentence start ");
//Create bookmark
Bookmark bookmark = new Bookmark(document, "bookmark2");
para.Inlines.Add(bookmark.BookmarkRangeStart);
para.Inlines.AddText("text");
para.Inlines.Add(bookmark.BookmarkRangeEnd);
//Insert some content after bookmark
para.Inlines.AddText(" Sentence end.");
WordFile wordFile = new WordFile();
using (var stream = File.OpenWrite("AddBookmark2.docx"))
{
wordFile.Export(document, stream);
}
}
}
}