1. Products
  2.   Aspose.PDF
  3.   Aspose.PDF FOSS for Java

Aspose.PDF FOSS for Java

Create and manipulate PDF documents from Java — with annotations, form fields, page manipulation, and PDF/A compliance. MIT-licensed.

Free MIT-Licensed Java Library for PDF Creation and Manipulation

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 Structure and Page Management

  • Document API: Use the Document class to create new PDF documents. Existing documents can be accessed via Document(filePath) or Document(stream) constructors.
  • Page management: Add, access, and modify pages via PageCollection. Each Page exposes MediaBox, CropBox, rotation, resources, and content operators.
  • Metadata: Read and write document metadata via DocumentInfo and XmpMetadata.
  • PDF structure: Access underlying PDF objects through getParser(), getCatalog(), and getTrailer().
  • Embedded files: Manage embedded file collections with getEmbeddedFiles().

Common Document Processing Scenarios

  • PDF generation: Build documents programmatically by creating a Document and populating pages.
  • Document analysis: Access existing files for metadata inspection or form field enumeration.
  • Page manipulation: Resize, rotate, or reorder pages using PdfFileEditor and the Page API.
  • Batch workflows: Apply consistent transformations across multiple documents in server-side pipelines.

Annotations and Form Fields

  • Annotation hierarchy: The abstract Annotation class is the base for all annotations; concrete types include WidgetAnnotation, FreeTextAnnotation, HighlightAnnotation, and UnderlineAnnotation.
  • Interactive forms: Access the document form via Document.getForm() to enumerate or create ButtonField, CheckboxField, and RadioButtonField instances.
  • Widget appearance: Control visual properties through AppearanceCharacteristics — border color, background, rotation, and captions.
  • Form editing: Use FormEditor and FormElement for higher-level form manipulation.

Document Review and Collaboration

  • Markup annotations: Add highlight, underline, or free-text annotations to documents for review workflows.
  • Interactive forms: Build fillable documents with radio buttons, checkboxes, and push buttons for data capture.
  • Form data extraction: Read submitted form field values for server-side pipelines.
  • Archival compliance: Validate and fix documents for long-term archiving using ActionRules and ActionFixes.

Security and Content Operations

  • AES encryption: Encrypt and decrypt data byte arrays with AESCipher using CBC mode (AESCipher.encrypt(key, data) and AESCipher.decrypt(key, data)).
  • Artifact management: Identify and manipulate headers, footers, watermarks, and background images via the Artifact and ArtifactCollection APIs.
  • Content resize: Adjust page content layout with PdfFileEditor.resizeContents() and ContentsResizeParameters.
  • Compliance validation: Validate annotation and action rules against PDF/A standards using AnnotationRules and ActionRules.

Document Security Use Cases

  • Encrypted payloads: Use AESCipher to encrypt data sections embedded in document streams.
  • Document protection: Apply security settings for access control in compliance workflows.
  • Watermarking: Detect and manage Artifact objects representing watermarks and page decorations.
  • Archival compliance: Run ActionFixes and AnnotationFixes to make existing documents meet PDF/A-1b archival standards.

Create a Document with Widget Annotation

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");
}

Create a Form with Radio Buttons

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");
}

Inspect Document Page Dimensions

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);
}
  

Support and Learning Resources