Last active
November 4, 2022 15:31
How to Add Bookmark in Word using C#. For more details: https://kb.aspose.com/words/net/how-to-add-bookmark-in-word-using-csharp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Words; | |
namespace AsposeProjects | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main function to add bookmark in Word document using C# | |
{ | |
// Initialize license | |
License lic = new License(); | |
lic.SetLicense("Aspose.Total.lic"); | |
// Create a new document | |
Document doc = new Document(); | |
// Create a document builder object | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
// Start a bookmark and add some text | |
builder.StartBookmark("My Bookmark"); | |
builder.Writeln("Text inside a bookmark."); | |
// Start and end a nested bookmark with some text | |
builder.StartBookmark("Nested Bookmark"); | |
builder.Writeln("Text inside a NestedBookmark."); | |
builder.EndBookmark("Nested Bookmark"); | |
// Write text after the nested bookmark and end the external bookmark | |
builder.Writeln("Text after Nested Bookmark."); | |
builder.EndBookmark("My Bookmark"); | |
doc.Save("Output.docx"); | |
System.Console.WriteLine("Done"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment