Make a booklet from a PDF document in Java

Import Dependency

Method 1: Download the free API and unzip it. Then add the Spire.Pdf.jar file to your project as dependency.
Method 2: Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>

Sample Code

The PdfDocument.createBooklet( String fileName, float width, float height, boolean doubleSide) method offered by Free Spire.PDF for Java allows you to turn a PDF document to a printable booklet. The complete sample code are shown as below.

import com.spire.pdf.*;

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

//Create a PdfDocument INSTANCE
PdfDocument pdf = new PdfDocument();

//Load a sample PDF document
pdf.loadFromFile("Sample.pdf");

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

//Set the width and height of the page
float width = (float) page.getSize().getWidth()*2;
float height = (float) page.getSize().getHeight();

//Create a booklet
pdf.createBooklet("Sample.pdf", width, height,true);

//Save the result document
pdf.saveToFile("Booklet.pdf");
}
}

--

--

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