Solutions

Read and write PDF annotations.

Parse, create, and modify comments, highlights, stamps, and ink annotations. Compliant with PDF spec section 12.5.

Code example

rust
use pdfluent::{Sdk, Annotation, HighlightAnnotation, Rect, Color};

fn main() -> pdfluent::Result<()> {
    let sdk = Sdk::new()?;
    let mut doc = sdk.open("input.pdf")?;

    let annot = HighlightAnnotation::builder()
        .page(0)
        .rect(Rect::new(72.0, 680.0, 300.0, 695.0))
        .color(Color::rgb(1.0, 0.93, 0.0))
        .author("Alice")
        .contents("Key clause")
        .build();

    doc.page_mut(0)?.add_annotation(annot)?;
    doc.save("annotated.pdf")?;

    Ok(())
}

Run cargo add pdfluent@1.0.0-beta.5 to get started.

What it does

All standard annotation types

Supports Highlight, Underline, StrikeOut, Squiggly, FreeText, Stamp, Ink, Line, Square, Circle, and Popup annotations. Each type maps directly to the annotation subtypes in PDF spec section 12.5.6.

Reading existing annotations

Iterate over all annotations on a page with page.annotations(). Each annotation exposes its subtype, rectangle, color, author, creation date, and modification date.

Adding annotations

Add annotations with page.add_annotation(). Set all required and optional fields via builder methods. PDFluent writes the correct PDF dictionary structure and assigns a unique object ID.

Appearance streams

Read and replace appearance streams (AP entries) on any annotation. PDFluent parses existing AP streams and can generate default appearances for highlights and stamps based on the annotation rectangle and color.

Deleting annotations

Remove annotations by index or by object ID with page.remove_annotation(). The underlying PDF objects are removed on the next garbage-collection pass during save.

Annotation import and export

Export all annotations from a document to a JSON or FDF representation. Re-import them into the same or a different document. Useful for annotation round-trips in review workflows.

Deployment options

Server-sideAWS LambdaWASM

Frequently asked questions