Text Annotation Class

Table of Contents

  1. Introduction
    1. Methods
      1. Example

        Introduction

        A text annotation represents a "sticky note" attached to a point on a page. It shall appear as an icon and additionally a popup when it is opened. It implements the markup annotation.

        Methods

        The class implements getter and setter methods to access text annotation data:

        getIconName()

        Get the icon name of the annotation.

        getState()

        Get the annotation state.

        getStateModel()

        Get the state model.

        isOpen()

        Checks if the annotation shall initially be displayed open.

        setIconName()

        Set the name of the icon that shall be used in displaying the annotation.

        setOpen()

        Sets whether the annotation shall initially be displayed open or not.

        setState()

        Set the annotation state.

        setStateModel()

        Set the annotation model.

        Example

        PHP
        <?php
        require_once('library/SetaPDF/Autoload.php');
        
        $writer = new \SetaPDF_Core_Writer_Http('text-annotation.pdf', true);
        $document = new \SetaPDF_Core_Document($writer);
        
        // let's create a page
        $pages = $document->getCatalog()->getPages();
        $page = $pages->create(\SetaPDF_Core_PageFormats::A4);
        
        $annotations = $page->getAnnotations();
        
        // create the text annotation
        $annotation = new \SetaPDF_Core_Document_Page_Annotation_Text(array(50, 680, 70, 700));
        $annotation->setContents("A simple text annotation.");
        $annotation->setTextLabel("John Dow"); // Used as Author in a Reader application
        $annotation->setColor(array(1, 0, 0));
        $annotation->setIconName(\SetaPDF_Core_Document_Page_Annotation_Text::ICON_HELP);
        $annotation->setSubject('A sticky note');
        $annotations->add($annotation);
        
        // create the popup
        $popup = $annotation->createPopup();
        $annotations->add($popup);
        // assign the popup to the text annotation
        $annotation->setPopup($popup);
        
        $document->save()->finish();