Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Annotations

Add, list, and remove PDF annotations.

Annotation Types

TypeDescription
HighlightHighlight text
UnderlineUnderline text
StrikeoutStrike through text
SquigglySquiggly underline
TextSticky note
FreeTextText box
LineLine shape
SquareRectangle shape
CircleEllipse shape
InkFreehand drawing
StampStamp annotation
LinkHyperlink

Adding Annotations

#![allow(unused)]
fn main() {
use printwell::annotations::{Annotation, AnnotationType, add_annotations};

let annotations = vec![
    Annotation::highlight(1, 100.0, 700.0, 200.0, 20.0)
        .color(255, 255, 0)
        .opacity(0.5),

    Annotation::sticky_note(1, 50.0, 600.0, "Review this")
        .author("Reviewer"),

    Annotation::new(AnnotationType::Square)
        .page(1)
        .rect(100.0, 500.0, 150.0, 100.0)
        .color(255, 0, 0),
];

let result = add_annotations(&pdf_data, &annotations)?;
}

Listing Annotations

#![allow(unused)]
fn main() {
use printwell::annotations::list_annotations;

let annotations = list_annotations(&pdf_data)?;

for ann in &annotations {
    println!(
        "Page {}: {:?} at ({}, {})",
        ann.page, ann.annotation_type, ann.rect.x, ann.rect.y
    );
}
}

Removing Annotations

#![allow(unused)]
fn main() {
use printwell::annotations::remove_annotations;

// Remove all annotations
let result = remove_annotations(&pdf_data, None, None)?;

// Remove from specific page
let result = remove_annotations(&pdf_data, Some(1), None)?;

// Remove specific types
let result = remove_annotations(
    &pdf_data,
    None,
    Some(&[AnnotationType::Highlight, AnnotationType::Underline])
)?;
}

Node.js Example

import { addAnnotations, listAnnotations, removeAnnotations } from 'printwell';

const result = addAnnotations(pdfData, [
    {
        type: 'Highlight',
        page: 1,
        rect: { x: 100, y: 700, width: 200, height: 20 },
        color: { r: 255, g: 255, b: 0 },
        opacity: 0.5
    }
]);

const annotations = listAnnotations(pdfData);
const cleaned = removeAnnotations(pdfData, { types: ['Highlight'] });

Python Example

from printwell import (
    add_annotations, list_annotations, remove_annotations,
    Annotation, AnnotationType
)

result = add_annotations(pdf_data, [
    Annotation.highlight(page=1, x=100, y=700, width=200, height=20)
])

annotations = list_annotations(pdf_data)
cleaned = remove_annotations(pdf_data, annotation_types=[AnnotationType.Highlight])