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

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_CARET = 'Caret'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_CIRCLE = 'Circle'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_FILE_ATTACHMENT = 'FileAttachment'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_FREE_TEXT = 'FreeText'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_HIGHLIGHT = 'Highlight'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_INK = 'Ink'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_LINE = 'Line'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_LINK = 'Link'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_MOVIE = 'Movie'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_POLYGON = 'Polygon'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_POLY_LINE = 'PolyLine'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_POPUP = 'Popup'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_PRINTER_MARK = 'PrinterMark'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_REDACT = 'Redact'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_SCREEN = 'Screen'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_SOUND = 'Sound'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_SQUARE = 'Square'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_SQUIGGLY = 'Squiggly'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_STAMP = 'Stamp'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_STRIKE_OUT = 'StrikeOut'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_TEXT = 'Text'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_TRAP_NET = 'TrapNet'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_UNDERLINE = 'Underline'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_WATERMARK = 'Watermark'

Annotation type

public const string SetaPDF_Core_Document_Page_Annotation::TYPE_WIDGET = 'Widget'

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