Images, Headers and Footers

Harry · 24 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Adding an Image

import com.itextpdf.layout.element.Image;
import com.itextpdf.io.image.ImageDataFactory;

Image logo = new Image(ImageDataFactory.create("logo.png"));
logo.setWidth(120);
document.add(logo);

Logo image above page content with footer

Page Headers and Footers

int pages = pdf.getNumberOfPages();
for (int i = 1; i <= pages; i++) {
    Document d = new Document(pdf);
    d.showTextAligned(new Paragraph("Page " + i + " of " + pages),
        550, 20, i, TextAlignment.RIGHT, VerticalAlignment.BOTTOM, 0);
}

Add footers after the main content is written, once the page count is known.

Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in