In this short article, you will learn how to eliminate page breaks in Word using Java. It has all the details to set the development environment, a list of tasks to be performed in the application, and a ready-to-run sample code to remove page breaks in Word using Java. It describes different types of page breaks that can be removed using the given sample code.
Steps to Remove All Page Breaks in Word using Java
- Set the IDE to use Aspose.Words to remove page breaks
- Open the target document and get access to the paragraphs
- Iterate through all the paragraphs to find and remove page breaks before each paragraph
- Within a paragraph iterate through all the runs to find page breaks and remove them
- Save the resultant Word file after removing all the page breaks
These steps assist in how to delete page break in Word using Java. The process is commenced by accessing and iterating all the paragraphs in the loaded Word file followed by finding and removing the page breaks before each paragraph. Afterward, each run in the individual paragraph is tested for containing any page break and replacement with an empty string before saving the final document.
Code to Eliminate Page Breaks in Word using Java
This sample code demonstrates the process of how to remove all page breaks in Word using Java. It uses NodeType.PARAGRAPH enumerator value to filter the paragraphs from the document however you may use other values to access different nodes. The ControlChar.PAGE_BREAK enumerator value is used at the end to find page breaks in each run of the paragraph whereas you may use LINE_BREAK_CHAR, PARAGRAPH_BREAK_CHAR, or COLUMN_BREAK_CHAR to find and remove other types of breaks.
In this article, we have learned how to remove the page break in Word using Java. If you are inclined to learn the process to remove comments from a Word file, refer to the article on how to delete comments from Word document in Java.