When we print a huge PDF document, print as a booklet is a great way to save the paper and make the pages tidy. This article we will introduce how to create a booklet from a PDF document in Java applications.
import com.spire.pdf.*; public class PDFBooklet{ public static void main(String[] args) throws Exception { String inputPath = "Sample.pdf"; PdfDocument doc = new PdfDocument(); doc.loadFromFile(inputPath); PdfPageBase page = doc.getPages().get(0); float width = (float) page.getSize().getWidth()*2; float height = (float) page.getSize().getHeight(); doc.createBooklet(inputPath, width, height,true); doc.saveToFile("Output/Booklet.pdf"); } }
Effective screenshot after creating PDF booklet: