Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
||||||||||||||||||||||||||







Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
One of the less highlighted enhancements in Version 3.2 of PDFOne Java were the improvements in autopagination.
Previously, autopagination occured when a PdfDocument was created or when autopagination property was set to true and a rendering operation on the document causes the content to overflow and a new page got created.
In Version 3.2, autopagination can be manually called using a new method PdfDocument.addPageBreak(). Before using this method, you need to know more as this method behaves differently in creation mode and writing mode.
When you create a new document with PdfDocument, a blank page is created by default in the document. This page becomes the focus of subsequent rendering operations - for all PdfDocument methods that do not have a page range argument, such as PdfDocument.writeText().
If you need a new page similar to the above-mentioned blank page, then call the new PdfDocument.addPageBreak() method. The method will create a new page and append it after the current page. The new page will then become the focus of rendering operations.
Here is a code example that illustrates creation-mode pagination.
import java.io.IOException;
import com.gnostice.pdfone.PdfAutoPageCreationHandler;
import com.gnostice.pdfone.PdfDocument;
import com.gnostice.pdfone.PdfException;
import com.gnostice.pdfone.PdfMeasurement;
import com.gnostice.pdfone.PdfPage;
import com.gnostice.pdfone.PdfPageSize;
import com.gnostice.pdfone.PdfWriter;
public class PdfDocument_addPageBreak_Example
implements PdfAutoPageCreationHandler {
public static void main(String[] args)
throws IOException, PdfException {
// Create a blank new document
PdfDocument d = new PdfDocument();
// Add a page to the document
PdfPage p = new PdfPage(PdfPageSize.A4);
d.add(p);
// If the above two lines are not used, then
// the onAutoPageCreation event will be called
// for both page 1 and 2
// Make pagination manual
d.setAutoPaginate(false);
// Set user class to raise onAutoPageCreation event
// when a new page is created
d.setAutoPageCreationHandler(
new PdfDocument_addPageBreak_Example());
// Write text on page 1
d.writeText("Hello, world!", 30, 50);
// Add a new page
d.addPageBreak();
// Write text on newly added page (2)
d.writeText("Hello again, world!", 30, 50);
d.setOpenAfterSave(true);
// Write document to file
d.save("PdfDocument_addPageBreak.pdf");
d.close();
}
public double[] onAutoPageCreation(
PdfDocument d, int creatingPageNum) {
// Change the page dimensions and margins of the new page
double[] new_page_sizes = new double[10];
new_page_sizes[0] = PdfPageSize.CUSTOM; // page size
new_page_sizes[1] = 8; // width
new_page_sizes[2] = 3; // height
new_page_sizes[3] = 0; // header size
new_page_sizes[4] = 0; // footer size
new_page_sizes[5] = 2; // left margin
new_page_sizes[6] = 1; // top margin
new_page_sizes[7] = 2; // right margin
new_page_sizes[8] = 1; // bottom margin
new_page_sizes[9] = PdfMeasurement.MU_INCHES; // measurement unit
// return new page settings
return new_page_sizes;
}
}
In reading mode, where an existing document is opened, the new method behaves differently. The first page will be the focus of rendering operations as usual. But, when you call PdfDocument.addPageBreak(), the focus will shift to the next page but no new page will be created. If a second page did not exist, only then a new page will be created.
---o0O0o---
| Our .NET Developer Tools | |
|---|---|
Gnostice Document Studio .NETMulti-format document-processing component suite for .NET developers. |
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
| Our Delphi/C++Builder developer tools | |
|---|---|
Gnostice Document Studio DelphiMulti-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms. |
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
|
| Our Java developer tools | |
|---|---|
Gnostice Document Studio JavaMulti-format document-processing component suite for Java developers. |
PDFOne (for Java)A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications. |
| Our Platform-Agnostic Cloud and On-Premises APIs | |
|---|---|
StarDocsCloud-hosted and On-Premises REST-based document-processing and document-viewing APIs |
| Privacy | Legal | Feedback | Newsletter | Blog | Resellers | © 2002-2026 Gnostice Information Technologies Private Limited. All rights reserved. |