Drawing Shapes

Shape Drawing

Aspose.PDF FOSS for Java exposes geometric shapes primarily through the annotation layer. CircleAnnotation draws an ellipse at a given Rectangle on a page.

try (Document doc = new Document()) {
    Page page = doc.getPages().add();
    CircleAnnotation circle = new CircleAnnotation(page,
        new Rectangle(100, 100, 200, 200));
    circle.setColor(Color.fromRgb(0, 0, 1));
    page.getAnnotations().add(circle);
    doc.save("shapes.pdf");
}

Artifacts

The Artifact class models page decorations: headers, footers, watermarks, and background images. ArtifactCollection, accessible via page resources, allows enumeration and removal of existing artifact objects.

try (Document doc = new Document("input.pdf")) {
    Page page = doc.getPages().get(1);
    // Enumerate artifacts (watermarks, headers, footers)
    for (Artifact artifact : page.getArtifacts()) {
        System.out.println(artifact.getArtifactType());
    }
}

Use ArtifactCollection.delete(artifact) to remove specific artifacts without modifying the page content stream directly.

See Also