Split a PDF Page into Multiple Pages in Java

PDF files containing multiple pages can be split into multiple different PDF files using Free Spire.PDF for Java, and if you want to split a PDF page into multiple pages, the free library is also capable of doing that.

Import Dependency


Sample Code

import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import java.awt.geom.Point2D;

public class SplitPDF {
public static void main(String[] args) throws Exception {

//Create an object of PdfDocument class.
PdfDocument pdf = new PdfDocument();

//Load the sample PDF document

//Get the first page of PDF
PdfPageBase page = pdf.getPages().get(0);

//Create a new PDF document and remove page margins
PdfDocument newPdf = new PdfDocument();

//Horizontally Split
newPdf.getPageSettings().setWidth((float) page.getSize().getWidth());
newPdf.getPageSettings().setHeight((float) page.getSize().getHeight()/2);

////Vertically Split
//newPdf.getPageSettings().setWidth((float) page.getSize().getWidth()/2);
//newPdf.getPageSettings().setHeight((float) page.getSize().getHeight());

// Add a new page to the new PDF document
PdfPageBase newPage = newPdf.getPages().add();

//Set the PdfLayoutType to Paginate to make the content paginated automatically
PdfTextLayout layout = new PdfTextLayout();

//Draw the content of source page in the new page
page.createTemplate().draw(newPage, new Point2D.Float(0, 0), layout);

//Save the Pdf document



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store