Annotations Access, edit and create annotations

Introduction

The PDF format allows you to associate objects such as a note, or a link with a location on a page of a PDF document. This is done with annotations. The PDF format includes a wide variety of standard annotation types. The SetaPDF-Core component allows you to access all types of annotations at a deep level but also comes with high level implementations allowing almost full control over annotation objects.

The Annotations Helper

Annotations are related to individual pages. The page object offers the getAnnotation() method to get access to the helper instance that manages all annotations of a single page:

PHP
$pages = $document->getCatalog()->getPages();
$page = $pages->getPage(1);
$annotations = $page->getAnnotations();

This helper instance offers various methods to get instances of attached annotations: 

getAll()

Get all annotations of this page.

getByName()

Get an annotation by its name (NM entry)

Or let you add or remove annotations: 

add()

Adds an annotation to the page.

remove()

Removes an annotation from the annotation array of the page.

Annotation Types

The annotation types are specified in the PDF format (as subtypes) and are represented as constants in the SetaPDF_Core_Document_Page_Annotation class: 

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Annotation type

Getting Annotations By Their Type

The getAll() method allows you to pass a type to filter the annotations appropriate. Just pass one of the constants to the getAll() method to filter by this type.

To e.g. only fetch link annotations you could use this line: 

PHP
$links = $annotations->getAll(SetaPDF_Core_Document_Page_Annotation::TYPE_LINK);