Page Elements

This guide shows how to work with page geometry, artifact decorations, and embedded file attachments in Aspose.PDF FOSS for Java. You will learn to read page dimensions via getMediaBox(), enumerate Artifact objects, and manage EmbeddedFileCollection.

Page Geometry

Each Page exposes its geometry through box properties:

  • getMediaBox() — the full page boundary
  • getCropBox() — the visible area
  • getRotate() — page rotation in degrees (0, 90, 180, or 270)

Read width and height from the media box to calculate positions for content placement:

try (Document doc = new Document("input.pdf")) {
    PageCollection pages = doc.getPages();
    Page page = pages.get(1);
    double width  = page.getMediaBox().getWidth();
    double height = page.getMediaBox().getHeight();
    System.out.println("Page size: " + width + " x " + height + " pt");
}

Standard A4 is 595 × 842 points; US Letter is 612 × 792 points.

Artifacts

The Artifact class models page decorations: headers, footers, watermarks, and background images. Artifacts are non-content elements defined in the PDF specification.

Iterate the artifact collection of a page to inspect type and subtype of each decoration:

try (Document doc = new Document("input.pdf")) {
    PageCollection pages = doc.getPages();
    Page page = pages.get(1);
    for (Artifact artifact : page.getArtifacts()) {
        System.out.println(artifact.getArtifactType() + " / " + artifact.getSubtype());
    }
}

Embedded Files

EmbeddedFileCollection, accessible via Document.getEmbeddedFiles(), manages file attachments embedded in the PDF document. Use size() to count attachments.

try (Document doc = new Document("document.pdf")) {
    EmbeddedFileCollection files = doc.getEmbeddedFiles();
    int count = files.size();
    System.out.println("Embedded files: " + count);
}

Page Count

Use PageCollection.getCount() or PageCollection.size() to determine the total number of pages in a document:

try (Document doc = new Document("input.pdf")) {
    int pageCount = doc.getPages().getCount();
    System.out.println("Total pages: " + pageCount);
}

See Also

 English