This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/flutter/annotations/create-edit-and-remove/programmatic.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Create PDF annotations in Flutter SDK

Nutrient Flutter SDK provides methods to get, add, and remove annotations programmatically using annotation model classes(opens in a new tab). Access these methods from the loaded document’s annotation manager (controller.document.annotations), which is available from the NutrientDocumentView onControllerReady callback.

The getAnnotations(opens in a new tab) method returns typed annotation models. To get annotations as an Instant JSON string instead, use getAnnotationsJson(pageIndex, type) or getUnsavedAnnotationsJson().

Use these annotation manager methods to retrieve, add, and remove annotations:

MethodDescription
getAnnotations(int pageIndex, [AnnotationType type = AnnotationType.all])Gets all annotations on the given page index, optionally filtered by type. Defaults to all supported annotation types(opens in a new tab).
getUnsavedAnnotations()Gets all unsaved annotations from the entire document.
addAnnotation(Annotation annotation)Adds the given annotation to the document.
removeAnnotation(int pageIndex, String annotationId)Removes the annotation with the given ID from the given page.

Get all annotations

The following example gets all annotations on the first page of a document:

List<Annotation> allAnnotations = await controller.document.annotations.getAnnotations(0, AnnotationType.all);
print(allAnnotations);

Remove all annotations

The following example removes an array of annotations from a document:

List<Annotation> allAnnotations = await controller.document.annotations.getAnnotations(0, AnnotationType.all);
print(allAnnotations);
// Make sure at least one annotation exists in the document.
// Remove the first annotation.
await controller.document.annotations.removeAnnotation(0, allAnnotations[0].id!);
print(allAnnotations);

Add annotations

The following examples show how to create different types of annotations in Flutter PDF documents using Nutrient.

Refer to the link annotation API reference(opens in a new tab) for available properties. The following example creates a link annotation:

// Create a new link annotation with a URL.
final linkAnnotation = LinkAnnotation(
id: 'link-annotation-1',
bbox: [50.0, 700.0, 200.0, 30.0],
createdAt: '2025-01-08T12:08:57+03:00',
action: UriAction(
uri: 'https://nutrient.io',
),
pageIndex: 0,
creatorName: 'Nutrient Flutter',
);
// Add the annotation to the document.
await controller.document.annotations.addAnnotation(linkAnnotation);

Highlight annotations

Refer to the highlight annotation API reference(opens in a new tab) for available properties. The following example creates a highlight annotation:

// Create a highlight annotation.
final highlightAnnotation = HighlightAnnotation(
id: 'highlight-annotation-1',
bbox: [50.0, 450.0, 200.0, 20.0],
createdAt: '2025-01-07T16:49:18+03:00',
color: const Color(0xFFFFEB3B),
rects: [
[50.0, 450.0, 200.0, 470.0],
],
opacity: 0.5,
pageIndex: 0,
creatorName: 'Nutrient Flutter',
);
await controller.document.annotations.addAnnotation(highlightAnnotation);

Free text annotations

Refer to the free text annotation API reference(opens in a new tab) for available properties. The following example creates a free text annotation:

// Create a free text annotation.
final freeTextAnnotation = FreeTextAnnotation(
id: 'freetext-annotation-1',
bbox: [50.0, 650.0, 200.0, 50.0],
createdAt: '2025-01-07T16:46:01+03:00',
text: TextContent(
format: TextFormat.plain,
value: 'This is a free text annotation',
),
fontColor: const Color(0xFF000000),
fontSize: 20,
font: 'sans-serif',
pageIndex: 0,
creatorName: 'Nutrient Flutter',
backgroundColor: const Color(0xFFFF0000),
horizontalTextAlign: HorizontalTextAlignment.left,
verticalAlign: VerticalAlignment.top,
);
await controller.document.annotations.addAnnotation(freeTextAnnotation);

Ink annotations

Refer to the ink annotation API reference(opens in a new tab) for available properties. The following example creates an ink annotation:

// Create an ink annotation with drawing points.
final inkAnnotation = InkAnnotation(
id: 'ink-annotation-1',
bbox: [267.4, 335.1, 97.2, 10.3],
createdAt: '2025-01-06T16:36:59+03:00',
lines: InkLines(
points: [
[
[269.4, 343.4],
[308.4, 341.7],
[341.2, 339.6],
[358.8, 339.6],
[360.9, 339.2],
[362.6, 338.8],
[361.7, 337.1],
]
],
intensities: [
[1.0, 0.43, 0.64, 0.83, 0.98, 0.99, 0.97]
],
),
lineWidth: 4,
opacity: 1.0,
flags: [AnnotationFlag.print],
creatorName: 'Nutrient Flutter',
isDrawnNaturally: false,
strokeColor: const Color(0xFF2492FB),
pageIndex: 0);
await controller.document.annotations.addAnnotation(inkAnnotation);

Note annotations

Refer to the note annotation API reference(opens in a new tab) for available properties. The following example creates a note annotation:

// Create a note annotation.
final noteAnnotation = NoteAnnotation(
id: 'note-annotation-1',
bbox: [400.0, 450.0, 32.0, 32.0],
createdAt: '2025-01-07T16:49:18+03:00',
text: TextContent(value: 'This is a note', format: TextFormat.plain),
color: const Color(0xFFFF9800),
pageIndex: 0,
creatorName: 'Nutrient Flutter',
);
await controller.document.annotations.addAnnotation(noteAnnotation);

Stamp annotations

Refer to the stamp annotation API reference(opens in a new tab) for available properties. The following example creates a stamp annotation:

// Create a stamp annotation
final stampAnnotation = StampAnnotation(
id: 'stamp-annotation-1',
bbox: [50.0, 650.0, 50.0, 50.0],
stampType: StampType.approved,
pageIndex: 0);
await controller.document.annotations.addAnnotation(stampAnnotation);

Image annotations

Refer to the image annotation API reference(opens in a new tab) for available properties. The following example creates an image annotation:

// Example of a square annotation.
final imageAnnotation = ImageAnnotation(
id: 'image-annotation-1',
bbox: [300.0, 750.0, 100.0, 100.0],
createdAt: '2025-01-08T12:08:57+03:00',
imageAttachmentId:
'303c4baa3d6adfcb12cd71e7060d6714850fa9c5404270fde637e43606352580',
pageIndex: 0,
creatorName: 'Nutrient Flutter',
attachment: const AnnotationAttachment(
id: '303c4baa3d6adfcb12cd71e7060d6714850fa9c5404270fde637e43606352580',
contentType: 'image/jpeg',
binary:
'/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCADIAMgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RF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ACvWP2eviTbeAfEF1Dq+/8AsbUVVZpEBYwOudr46kfMQQB6HnGD5PRQDVz9Cm+Ivg0ad9uPijR/s2M5+1pu+m3O7PtjNfJH7QPxHg+IHiW2XSlcaPpytHbs42mZmxukI7A7VAHXA7ZwPLKKBJWCiiigYUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAf/2Q==',
),
)
await controller.document.annotations.addAnnotation(imageAnnotation);

Add multiple annotations

Add multiple annotations by iterating over a list:

final annotations = [
noteAnnotation,
highlightAnnotation,
inkAnnotation,
];
for (final annotation in annotations) {
await controller.document.annotations.addAnnotation(annotation);
}