In this tutorial you’ll learn how to use Java WordsApi to extract specific pages from a DOCX document with the Aspose.Words Cloud Java SDK and save the result as a new Word file. For detailed information about the DOCX format, visit the DOCX file info page.
Prerequisite
- Create an account and get API credentials
- Download the Aspose.Words Cloud SDK for Java to work with Word ranges
- Set up a Java project and add the SDK as a dependency
Steps to Extract Page from Word Document with Java Low Code API
- Initialize the WordsApi class object to work with the Word file
- Create a request object using the SaveAsRangeOnlineRequest class
- Load the source Word file into the request object
- Define the start and end identifiers for the range you want to extract
- Call the SaveAsRangeOnline() method to extract the defined range
- Save the returned Word file that contains only the selected pages
The steps above outline how to extract pages from a Word document with Java Low Code API. Begin by creating a WordsApi instance, then build a SaveAsRangeOnlineRequest with the input file bytes, range start identifier, range end identifier, and the desired output file name. Invoke SaveAsRangeOnline() with this request and write the response stream to a new DOCX file.
Code for Word Page Extractor with Java REST API
The sample code demonstrates how to save pages as DOCX with Java Low Code API. By providing range identifiers—page2 (start at page 2), page2:end (end at page 2), document:end (end of the document), or a node path such as id0.0.0—you can extract any segment of the source document and save it as a separate Word file.
Looking to pull metadata from a Word document? Explore our companion guide: Extract Metadata from Word Document with Java REST API.
In summary, this guide covered how to extract pages from Word with NET REST API; how to save pages as DOC with Java Low Code API; how to save pages as DOCX with Java REST API; how to convert pages to Microsoft Word with Java Low Code API; and how to extract text from a Word document with Java REST API.