The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Use an iText 5 PdfPageEventHelper and draw the footer in onEndPage(PdfWriter, Document). Register the event once with writer.setPageEvent(...), then write to writer.getDirectContent(). The callback runs as a page is finished; it does not need—and should not call—document.newPage(). Drawing on the writer canvas keeps the footer outside the document’s normal text and table layout.
How to add text as a footer in iText 5
The page event is the right place for content that should be drawn on each page as that page is finalized. For a short, single-line footer, use ColumnText.showTextAligned. Its position is specified by an x-coordinate, a y-coordinate and an alignment; the y-coordinate is the text baseline.
Here is a compact example. It writes one PDF with a centered, changing page number. The output stream, document and writer are created first; the event is registered before the document is opened.
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;
public class FooterExample {
private static class PageNumberFooter extends PdfPageEventHelper {
private final Font font = new Font(Font.FontFamily.HELVETICA, 9);
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte canvas = writer.getDirectContent();
Phrase text = new Phrase("Page " + writer.getPageNumber(), font);
float x = (document.left() + document.right()) / 2;
float y = document.bottom() - 18;
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, text, x, y, 0);
}
}
public static void main(String[] args) throws Exception {
Document document = new Document(PageSize.LETTER, 36, 36, 48, 54);
PdfWriter writer = PdfWriter.getInstance(
document, new FileOutputStream("output.pdf"));
writer.setPageEvent(new PageNumberFooter());
document.open();
document.add(new com.itextpdf.text.Paragraph(
"Add your ordinary document content here."));
document.close();
}
}
Replace the sample paragraph with the content your application normally adds. If that content flows to multiple pages, iText finishes each page and invokes the event for it. You do not need to add page-number paragraphs to the document yourself.
Recommended Free Tools
#1 Best Overall
- 1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
- Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
- Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
- Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
- Virgin copy paper providing professional quality results; acid-free to prevent yellowing
Why this does not start a new page
onEndPage is called when a page is finished, just before it is written to the document. The callback is for drawing on that page, not for adding another layout-flow element. Use the writer’s direct content canvas (or a bounded ColumnText drawing area) rather than adding a Paragraph, table or other element through document from inside the callback. Adding normal document content there can interfere with layout and pagination.
Do not call document.newPage() in the footer event. A page break is a separate document-building action. Normal content may overflow to a new page, or your document-building code may explicitly request one; the footer callback simply draws on each page as it is finalized.
Position the footer without overlapping content
The sample uses a document bottom margin of 54 points and places the footer baseline 18 points below document.bottom(). That relationship is more useful than copying a fixed y-coordinate: it ties the footer to the document’s content boundary and leaves space between body content and the footer. Coordinates are measured on the page, and the baseline—not the bottom edge of the letters—is what showTextAligned receives.
Rank #2
- HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America. Each ream is wrapped in a polyurethane coated paper wrapper to protect the cut sheets from moisture damage
- Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
- HP Copy&Print20 20 pounds printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design)
- All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment; 100% satisfaction guaranteed; ColorLok technology provides more vivid colors, bolder blacks and faster drying
- Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office; HP Copy&Print20 print and copy paper prevents yellowing over time to ensure a long-lasting appearance for added archival quality
- Choose a bottom margin large enough for the footer’s height and any desired gap.
- Position the footer below the content boundary but inside the page boundary.
- Recheck the coordinates when page size, margins, font size or footer content changes.
- Use
document.left()anddocument.right()for alignment relative to the usable content width, rather than assuming a page width.
The sample is centered. To align a short footer to one side, retain the relevant x-coordinate and change the alignment passed to showTextAligned to Element.ALIGN_LEFT or Element.ALIGN_RIGHT. For example, a left-aligned footer can use document.left(); a right-aligned one can use document.right(). Make sure the selected coordinate and alignment keep the complete text within the page.
Free tools Windows power users keep installed
One-click scans. No signup required.
Use a different value on different pages or sections
writer.getPageNumber() supplies the current page number when the callback runs. For other changing footer text—such as a section label—keep the value in a field on your event object and read it in onEndPage. Update that field in your document-building code when the intended section changes.
The timing matters at a section boundary: set the new value before the next page is started or finalized, so the next page’s callback sees the new value. iText’s dynamic-header example changes the event’s phrase before calling document.newPage(); the same ordering can be adapted to footer state. A footer that varies within one page needs a more specific design decision: a page event draws at page finalization, not at each paragraph’s position in the flow.
Rank #3
- 3 ream case (1,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
- Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
- Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
- Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
- Virgin copy paper providing professional quality results; acid-free to prevent yellowing
Show “Page X of Y” with a template placeholder
The final page count is not generally known when the first pages are being written. Use a PdfTemplate as a reserved blank area in the footer, then write the total into that template when the document closes. The current page number can still be drawn immediately in onEndPage.
import com.itextpdf.text.pdf.PdfTemplate;
private static class PageCountFooter extends PdfPageEventHelper {
private final Font font = new Font(Font.FontFamily.HELVETICA, 9);
private PdfTemplate totalPages;
@Override
public void onOpenDocument(PdfWriter writer, Document document) {
totalPages = writer.getDirectContent().createTemplate(30, 12);
}
@Override
public void onEndPage(PdfWriter writer, Document document) {
PdfContentByte canvas = writer.getDirectContent();
float x = (document.left() + document.right()) / 2;
float y = document.bottom() - 18;
Phrase prefix = new Phrase(
"Page " + writer.getPageNumber() + " of ", font);
ColumnText.showTextAligned(
canvas, Element.ALIGN_CENTER, prefix, x - 10, y, 0);
canvas.addTemplate(totalPages, x + 20, y - 3);
}
@Override
public void onCloseDocument(PdfWriter writer, Document document) {
// At close, getPageNumber() is the last page number plus one.
int total = writer.getPageNumber() - 1;
ColumnText.showTextAligned(
totalPages, Element.ALIGN_LEFT,
new Phrase(String.valueOf(total), font), 0, 2, 0);
}
}
Use new PageCountFooter() in place of the page-number event when registering the event. The template’s dimensions and placement must leave room for the widest expected total, and the surrounding text should be laid out to avoid collisions as page numbers gain digits. In onCloseDocument, the writer’s page number is one greater than the final page number; subtract one when writing the total.
The sample positions the phrase and template separately to make the placeholder visible as an approach, but the exact spacing depends on font, alignment and page-number widths. For a production footer with varying digit counts or carefully centered combined text, measure and compose the complete line deliberately rather than assuming a fixed gap will look centered on every page.
Rank #4
- 5 ream case (2,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
- Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
- Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
- Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
- Virgin copy paper providing professional quality results; acid-free to prevent yellowing
Choose a drawing method for the footer’s complexity
- One line of text:
ColumnText.showTextAlignedis compact and gives direct control of alignment and baseline. - Multiple lines or bounded text: use a
ColumnTextarea with defined bounds so the footer’s text is laid out within a controlled region. - Structured content: a table can be drawn using writer content for elements such as left, center and right footer sections. It should be drawn on the canvas, not added to the document’s ordinary flow from the page event.
- Final total-page count: use a template placeholder, since the total is not available while earlier pages are being written.
Troubleshoot missing, misplaced or incorrect footers
The footer appears at the top
Check that the position is based on document.bottom(), not document.top(). The latter is the top content boundary. Also check the sign and size of the offset: a footer baseline should be placed near the bottom of the page, with enough room below the content boundary.
No footer appears
- Confirm the event was registered on the same
PdfWriterthat writes the document, usingwriter.setPageEvent(event). - Confirm the override is
onEndPage(PdfWriter, Document). - Check that the coordinates fall inside the page and that the font and phrase contain visible content.
- Verify the document is actually producing a page and that the writer’s output is the PDF you are opening.
Pagination changes unexpectedly or the callback fails
Remove any call in the callback that adds a flow element through document. Draw with writer.getDirectContent() instead, and keep page creation or explicit breaks in the normal document-building code.
The footer overlaps body text
Increase the document’s bottom margin to reserve more room, then adjust the baseline within the page boundary. A footer positioned outside the body’s content area can still overlap content if the margin does not actually leave enough space for the footer’s full height.
Best Value
- Made in USA: HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America.
- Optimized for HP technology: All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment.
- Perfect everyday office paper: Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office. Perfect for everyday black and white printing.
- Certified sustainable: HP Office20 20lb printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design).
- ColorLok technology printing paper: ColorLok technology provides more vivid colors, bolder blacks and faster drying.
The “of Y” total is one too high
In onCloseDocument, account for the documented callback behavior: writer.getPageNumber() is the final page number plus one. Write writer.getPageNumber() - 1 into the template.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server, not an iText footer library or a replacement for implementing a PDF page event. If your workflow also needs website screenshots, its one-call API returns an image or PDF for a URL. See the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- It accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be turned off.
- Bot checks/CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed; responses identify the page verdict and billing status in headers.
- An MCP server provides
take_screenshot,get_page_infoandcapture_pdftools for AI agents, including Claude, Cursor and other MCP clients. - The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan.
Create a free ScreenshotNeo account if you need a separate website screenshot service. For iText 5 footers, use the page-event implementation above.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

