Aspose.PDF FOSS for Java is a MIT-licensed Java library for creating and working with PDF documents. It provides a comprehensive Document class as the central entry point, along with full coverage of annotations, interactive form fields, page manipulation, metadata, and PDF/A compliance validation.
The library exposes 527 classes covering the full PDF specification: document structure via Document, Page, and PageCollection; annotations through the Annotation hierarchy (including WidgetAnnotation, FreeTextAnnotation, and HighlightAnnotation); interactive forms with Form, ButtonField, CheckboxField, and RadioButtonField; page rendering via BmpDevice; and PDF/A compliance checking through ActionRules and ActionFixes. Encryption is provided via AESCipher in CBC mode.
Add Aspose.PDF FOSS to your Maven project using groupId org.aspose and artifactId aspose-pdf. The library requires Java 11 or later and is fully MIT-licensed. To work with PDF in Java production applications with form filling, annotation, PDF/A validation, and digital signing, see the Aspose.PDF — Enterprise Product Family.
Document class to create new PDF documents. Existing documents can be accessed via Document(filePath) or Document(stream) constructors.PageCollection. Each Page exposes MediaBox, CropBox, rotation, resources, and content operators.DocumentInfo and XmpMetadata.getParser(), getCatalog(), and getTrailer().getEmbeddedFiles().Document and populating pages.PdfFileEditor and the Page API.Annotation class is the base for all annotations; concrete types include WidgetAnnotation, FreeTextAnnotation, HighlightAnnotation, and UnderlineAnnotation.Document.getForm() to enumerate or create ButtonField, CheckboxField, and RadioButtonField instances.AppearanceCharacteristics — border color, background, rotation, and captions.FormEditor and FormElement for higher-level form manipulation.ActionRules and ActionFixes.AESCipher using CBC mode (AESCipher.encrypt(key, data) and AESCipher.decrypt(key, data)).Artifact and ArtifactCollection APIs.PdfFileEditor.resizeContents() and ContentsResizeParameters.AnnotationRules and ActionRules.AESCipher to encrypt data sections embedded in document streams.Artifact objects representing watermarks and page decorations.ActionFixes and AnnotationFixes to make existing documents meet PDF/A-1b archival standards.Create a new document, add a page, and attach a widget annotation with styling.
try (Document doc = new Document()) {
Page page = doc.getPages().add();
WidgetAnnotation w = new WidgetAnnotation(page, new Rectangle(0, 0, 100, 50));
w.getCharacteristics().setBorder(Color.fromRgb(1, 0, 0));
w.getCharacteristics().setCaption("Submit");
page.getAnnotations().add(w);
doc.save("output.pdf");
}
Add a radio button group to a document form and select a value programmatically.
try (Document doc = new Document()) {
Page page = doc.getPages().add();
RadioButtonField radio = new RadioButtonField(page);
radio.setPartialName("choice");
radio.addOption("Option1", new Rectangle(50, 50, 70, 70));
radio.addOption("Option2", new Rectangle(50, 80, 70, 100));
doc.getForm().add(radio, 1);
radio.setValue("Option2");
doc.save("form.pdf");
}
Access an existing document and read the media box dimensions of the first page.
try (Document doc = new Document("input.pdf")) {
double width = doc.getPages().get(1).getMediaBox().getWidth();
double height = doc.getPages().get(1).getMediaBox().getHeight();
System.out.println("Page size: " + width + " x " + height);
}