Java REST API enables you to programmatically insert a bookmark into a DOCX document using the Aspose.Words Cloud SDK for Java. In this guide you’ll learn how to configure the client, define bookmark ranges, and call the appropriate API methods to embed a bookmark in a Word file stored locally.
Prerequisite
- Create an account and get API credentials
- Download the Aspose.Words Cloud SDK for Java to add a bookmark in a Word file
- Set up a Java project and add the SDK as a dependency
Steps to Create Bookmark in Word with Java REST API
- Set Client ID and Client Secret for the API to add a bookmark.
- Instantiate an object of the WordsApi class with your client credentials.
- Read the source Word file into a memory stream for creating a bookmark.
- Define the start and end range of the bookmark using the PositionInsideNode class.
- Create the InsertBookmarkOnlineRequest object by providing the required parameters.
- Call the
InsertBookmarkOnlinemethod to insert a bookmark according to theInsertBookmarkOnlineRequest. - Save the resultant Word file with the new bookmark.
The steps above outline how to create a bookmark in Word with Java REST API. Begin by creating a WordsApi instance, read the source DOCX file, set the bookmark parameters, invoke the API, and finally save the updated document to your local disk.
Code to Insert a Bookmark in Word with Java REST API
This sample demonstrates how to add a bookmark in Word with Java REST API. The PositionInsideNode class specifies the start and end positions of the bookmark within the document. The API returns the updated document as a stream, which you can write to a file.
If you need to convert a Word file to another format, such as HTML, see the article on Convert DOCX to HTML with Java REST API.
Keywords: how to add bookmark in word with Java REST API; add bookmark in word with NET REST API; how to create a bookmark in word with Java Low Code API; create bookmark in word with NET REST API; automatically create bookmarks in word with Java Low Code API; add bookmark to word document with Java Low Code API; make a bookmark in word with Java REST API.