public interface PdfAutoPageCreationHandler
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
PdfWriter w = PdfWriter.fileWriter(
"PdfDocument_addPageBreak.pdf");
PdfDocument d = new PdfDocument(w);
// 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
// Set pagination to manual
d.autoPaginate = 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.write();
w.dispose();
}
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;
}
}
| Modifier and Type | Method and Description |
|---|---|
double[] |
onAutoPageCreation(PdfDocument d,
int creatingPageNum)
Called by implementing user classes to obtain the size and
margins that need to be applied to the new page that is
automatically created by a PdfDocument object or when
PdfDocument.addPageBreak()
is called. |
double[] onAutoPageCreation(PdfDocument d, int creatingPageNum)
PdfDocument.addPageBreak()
is called. The second and third array values, specifying the
width and height of the page, will be considered only when the
first array value, specifying the page size, is
PdfPageSize.CUSTOM. If null is returned by this
method, then the page will have the same dimensions as the page
that is before the new page. If page size was not explicitly
specified for the previous, then it must be of
PdfPageSize.LETTER size and the new page will be of the
same size.d - document in which the new page has been createdcreatingPageNum - number of the page that has been createdsize, width, height, header size,
footer size, left margin size, top margin size, right
margin size, bottom margin size, and measurement unit
with all other values need to be applied to the page