Skip to content

Commit 3f208c3

Browse files
Bold Create AgentDharanyaSakthivel-SF4210
andcommitted
Add sample for BookmarkEnd position APIs
Co-authored-by: DharanyaSakthivel-SF4210 <149999916+DharanyaSakthivel-SF4210@users.noreply.github.com>
1 parent 2987494 commit 3f208c3

5 files changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Control-bookmark-end-position", "Control-bookmark-end-position\Control-bookmark-end-position.csproj", "{A4C8E1B2-7D3F-4A91-9E56-1B2C3D4E5F60}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A4C8E1B2-7D3F-4A91-9E56-1B2C3D4E5F60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A4C8E1B2-7D3F-4A91-9E56-1B2C3D4E5F60}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A4C8E1B2-7D3F-4A91-9E56-1B2C3D4E5F60}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A4C8E1B2-7D3F-4A91-9E56-1B2C3D4E5F60}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B5D9F2C3-8E40-4BA2-AF67-2C3D4E5F6071}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Control_bookmark_end_position</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Output\.gitkeep">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
</ItemGroup>
18+
19+
</Project>

‎Bookmarks/Control-bookmark-end-position/.NET/Control-bookmark-end-position/Output/.gitkeep‎

Whitespace-only changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using System.IO;
4+
5+
namespace Control_bookmark_end_position
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
//Creates an instance of WordDocument class (Empty Word Document).
12+
using (WordDocument document = new WordDocument())
13+
{
14+
//Adds a section to the document.
15+
IWSection section = document.AddSection();
16+
//Adds a paragraph and preserves the bookmark end after the paragraph mark.
17+
IWParagraph paragraph = section.AddParagraph();
18+
paragraph.AppendBookmarkStart("ParagraphBookmark");
19+
paragraph.AppendText("Paragraph bookmark");
20+
BookmarkEnd bookmarkEnd = paragraph.AppendBookmarkEnd("ParagraphBookmark");
21+
bookmarkEnd.IsAfterParagraphMark = true;
22+
//Adds a 2 x 2 table.
23+
IWTable table = section.AddTable();
24+
table.ResetCells(2, 2);
25+
//Adds a bookmark end after the table-cell mark of the first cell.
26+
IWParagraph cellParagraph = table[0, 0].AddParagraph();
27+
cellParagraph.AppendBookmarkStart("CellBookmark");
28+
cellParagraph.AppendText("Cell bookmark");
29+
bookmarkEnd = cellParagraph.AppendBookmarkEnd("CellBookmark");
30+
bookmarkEnd.IsAfterCellMark = true;
31+
//Adds a bookmark end after the first table-row mark, in the final cell of that row.
32+
IWParagraph rowParagraph = table[0, 1].AddParagraph();
33+
rowParagraph.AppendBookmarkStart("RowBookmark");
34+
rowParagraph.AppendText("Row bookmark");
35+
bookmarkEnd = rowParagraph.AppendBookmarkEnd("RowBookmark");
36+
bookmarkEnd.IsAfterRowMark = true;
37+
//Adds content to the remaining cell without a bookmark end.
38+
table[1, 0].AddParagraph().AppendText("Content");
39+
//Adds a bookmark end after the table mark, in the final cell of the final row.
40+
IWParagraph tableParagraph = table[1, 1].AddParagraph();
41+
tableParagraph.AppendBookmarkStart("TableBookmark");
42+
tableParagraph.AppendText("Table bookmark");
43+
bookmarkEnd = tableParagraph.AppendBookmarkEnd("TableBookmark");
44+
bookmarkEnd.IsAfterTableMark = true;
45+
//Creates file stream.
46+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/BookmarkEndPositions.docx"), FileMode.Create, FileAccess.ReadWrite))
47+
{
48+
//Saves the Word document to file stream.
49+
document.Save(outputFileStream, FormatType.Docx);
50+
}
51+
}
52+
}
53+
}
54+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Control bookmark end position
2+
3+
This sample shows how to control bookmark-end positions in a Word document using the [.NET Word Library](https://www.syncfusion.com/document-sdk/net-word-library) (Essential DocIO).
4+
5+
The sample demonstrates these `BookmarkEnd` APIs:
6+
7+
- `IsAfterParagraphMark`
8+
- `IsAfterCellMark`
9+
- `IsAfterRowMark`
10+
- `IsAfterTableMark`
11+
12+
## Prerequisites
13+
14+
- [.NET SDK 8.0](https://dotnet.microsoft.com/download) or later
15+
- [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package
16+
17+
## How to run the sample
18+
19+
1. Open `Control-bookmark-end-position.sln` in Visual Studio, or open a terminal in the `Control-bookmark-end-position` project folder.
20+
2. Restore packages and run the project:
21+
22+
```
23+
dotnet run
24+
```
25+
26+
## Expected output
27+
28+
The sample creates `Output/BookmarkEndPositions.docx` with four bookmarks:
29+
30+
- `ParagraphBookmark` ends after the paragraph mark.
31+
- `CellBookmark` ends after the table-cell mark.
32+
- `RowBookmark` ends after the table-row mark.
33+
- `TableBookmark` ends after the table mark.
34+
35+
More information about bookmarks can be found in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-bookmarks) section.

0 commit comments

Comments
 (0)