This tutorial guides on how to insert page break in PDF using Java. It has the details to set the IDE, a list of steps, and a sample code showing how to add page break in PDF using Java in-between the existing text. You will learn to add multiple page breaks using a few API calls only without installing any third-party tool.
Steps to Add Page break to PDF using Java
- Set the IDE to use Aspose.PDF for Java to insert page breaks
- Open the source PDF file using the Document class object for adding page breaks
- Create an empty PDF file to save the output
- Create an object of the PdfFileEditor class to work with the PDF file
- Call the addPageBreak() method by providing the necessary input
- Save the output
Follow these steps depicting how to insert page break in Adobe PDF using Java. Load the source PDF file containing some text, create a new empty PDF file for storing the output, and create the PdfFileEditor class object. Call the addPageBreak() method and provide the source PDF file, output PDF file, and an array of page breaks with the page number and position of each page break.
Code to Add Page Break in PDF using Java
This code demonstrates how to insert a page break in Adobe PDF using Java. Each page break in the array requires the page number and number of pixels from the bottom. The addPageBreak() method has multiple overloaded methods that take input and output Document objects or file names of the input and output PDF files.
This article has taught us how to insert a page break in a PDF document using Java. For splitting a PDF file by pages, refer to the article on How to split PDF by pages in Java.