Page Setup Studio
Features 367 page numbers, 368 header/footer, 369 orientation and 370 paper size - plus the 366 watermark - on a real multi-page report. Every change re-renders the PDF on the right. Save the result as a preset and use it for invoices, templates and batch printing.
Live PDF
Saved presets
table print_preset| Name | Paper | Orientation | Margin | Header / footer | Page numbers | Watermark | |
|---|---|---|---|---|---|---|---|
| A4 Landscape report | A4 | LANDSCAPE | 12 mm | {company} - {title} Confidential - internal use |
{page} / {total} | - | |
| A5 Compact | A5 | PORTRAIT | 10 mm | {company} - |
{page}/{total} | - | |
| Clean (no header / footer) | A4 | PORTRAIT | 12 mm | - - |
- | - | |
| Draft copy (watermark) | A4 | PORTRAIT | 15 mm | {company} DRAFT - not valid as a tax document |
Page {page} of {total} | DRAFT | |
| Standard A4 default | A4 | PORTRAIT | 15 mm | {company} {title} | Printed {date} |
Page {page} of {total} | - | |
| US Letter | LETTER | PORTRAIT | 19 mm | {company} Printed {date} |
Page {page} | - |
How it works
- 370 / 369 -
PaperSize.toRectangle(orientation)converts millimetres to PDF points (1 mm = 72 / 25.4 pt) and swaps width and height for landscape. - 368 / 367 / 366 -
PageDecoratorextends OpenPDF'sPdfPageEventHelper.onEndPage()runs once per page and draws the header, footer, page number and watermark. - "of {total}" - the total is unknown on page 1, so it is drawn into a
PdfTemplateplaceholder and filled inonCloseDocument(). - Long tables call
table.setHeaderRows(1), so the column titles repeat at the top of each page.
public void onEndPage(PdfWriter writer, Document document) {
String text = format.replace("{page}", String.valueOf(writer.getPageNumber()));
...
cb.addTemplate(totalBox, x, y); // "{total}" placeholder
}
public void onCloseDocument(PdfWriter writer, Document document) {
totalBox.showText(String.valueOf(writer.getPageNumber() - 1));
}
SELECT name, paper_size, orientation, margin_mm, page_number_format, watermark_text, is_default
FROM print_preset ORDER BY name;
Files: print/PageSetup.java, print/PaperSize.java, print/PageDecorator.java, print/PdfKit.java, service/PresetService.java.