Work with Pages in PDF via Java

Manage PDF pages in document programmaticaly using Aspose.PDF for Java Library

Most popular action with Pages in Java

How to Insert pages to PDF Document Using Java

In order to add page, we’ll use Aspose.PDF for Java API which is a feature-rich, powerful and easy to use conversion API for Java platform. You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Add Page to PDF via Java


You need Aspose.PDF for Java to try the code in your environment.

  1. Create a Document object with the input PDF file.

  2. Call the PageCollection collection’s Insert method with specified index.

  3. Save the output PDF using the Save method.

Add New Page to PDF


    Document document = new Document();

    // Add page
    document.getPages().add();

    // Insert a empty page in a PDF
    document.getPages().insert(2);

    // Save updated PDF
    document.save(_dataDir + "InsertEmptyPage_out.pdf");