This step‑by‑step guide shows you how to extract text from a Word document with the .NET REST API. Using the C# Low Code API, you’ll programmatically retrieve the exact portion of a DOCX file you need by defining the start and end positions. The article covers multiple methods for setting range parameters, enabling precise text extraction.
Prerequisite
- Create an account and get API credentials
- Download Aspose.Words Cloud SDK for Dotnet to extract a range of text from a Word file
- Setup a C# solution project with the above SDK for saving a range to a string
Steps to Extract Specific Text from Word Document with NET REST API
- Create the WordsApi class object to extract a range of text from a Word file
- Instantiate the GetRangeTextOnlineRequest object and load the input Word file content in it
- Set the range parameters in the request object to define the start and end of the text range
- Call the GetRangeTextOnline method to extract the range of text
- Display the text from the response returned by the API call
The above steps describe the process to extract text from DOC with C# Low Code API. Commence the process by creating the WordsApi class object using the client ID and secret, and initiate the request object using the GetRangeTextOnlineRequest class. Fill in the parameters to define the range of text and use it while calling the GetRangeTextOnline() method that fetches data from the source file.
Code to Extract Text from DOCX with C# REST API
This example shows how to extract text from a Word document with the C# REST API. The GetRangeTextOnlineRequest lets you specify RangeStartIdentifier and RangeEndIdentifier to define the exact portion of the document you want to retrieve, and the result is stored in a string variable. Use identifiers such as page3 for page 3, page3:end for the end of page 3, and document:end for the end of the entire document.
In this guide we demonstrated how to pinpoint a text range that spans multiple pages and store it in a string variable. If you’d like to convert a Word page into an image, explore our related tutorial: Convert Word Page to Image with NET REST API.