Square and Circle Annotation Classes

Table of Contents

  1. Introduction
    1. Methods
      1. Example

        Introduction

        Square and circle annotations shall display, respectively, a rectablge or an ellipse on the page. The annotations are represented by the SetaPDF_Core_Document_Page_Annotation_Square and SetaPDF_Core_Document_Page_Annotation_Circle classes. 

        Methods

        The classes implements getter and setter methods to access the individual annotation data:

        getInteriorColor()

        Get the interior color.

        setInteriorColor()

        Set the interior color.

        Example

        PHP
        <?php
        require_once('library/SetaPDF/Autoload.php');
        
        $writer = new \SetaPDF_Core_Writer_Http('square-and-circle-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);
        
        // get access to the annotations helper
        $annotations = $page->getAnnotations();
        
        // create a new square annotation
        $square = new \SetaPDF_Core_Document_Page_Annotation_Square(array(50, 700, 150, 750));
        $square->setColor(array(1, 0, 0)); // border color
        $square->setInteriorColor(array(0, 0, 1)); // inner color
        $square->setContents("A simple square annotation.");
        $square->setTextLabel("John Dow"); // used as Author in a Reader application
        // style the border
        $borderStyle = $square->getBorderStyle(true);
        $borderStyle->setWidth(4);
        $borderStyle->setStyle(\SetaPDF_Core_Document_Page_Annotation_BorderStyle::DASHED);
        // add to the page annotations object
        $annotations->add($square);
        
        // create a new circle annotation
        $circle = new \SetaPDF_Core_Document_Page_Annotation_Circle(array(200, 700, 300, 750));
        $circle->setColor(array(0, 0, 1)); // border color
        $circle->setInteriorColor(array(1, 0, 1)); // inner color
        $circle->setContents("A simple circle annotation.");
        $circle->setTextLabel("John Dow"); // used as Author in a Reader application
        // style the border
        $borderStyle = $circle->getBorderStyle(true);
        $borderStyle->setWidth(2);
        $borderStyle->setStyle(\SetaPDF_Core_Document_Page_Annotation_BorderStyle::BEVELED);
        // add to the page annotations object
        $annotations->add($circle);
        
        // create another new square annotation
        $square = new \SetaPDF_Core_Document_Page_Annotation_Square(array(50, 600, 150, 650));
        $square->setColor(array(0, 1, 0)); // border color
        $square->setInteriorColor(array(1, 0, 1)); // inner color
        $square->setContents("A simple cloudy square annotation.");
        $square->setTextLabel("John Dow"); // used as Author in a Reader application
        // style the border
        $borderStyle = $square->getBorderStyle(true);
        $borderStyle->setWidth(2);
        // add a border effect
        $borderEffect = $square->getBorderEffect(true);
        $borderEffect->setName(\SetaPDF_Core_Document_Page_Annotation_BorderEffect::CLOUDY);
        $borderEffect->setIntensity(5);
        // add to the page annotations object
        $annotations->add($square);
        
        // create another new circle annotation
        $circle = new \SetaPDF_Core_Document_Page_Annotation_Circle(array(200, 600, 300, 650));
        $circle->setColor(array(0, 1, 1)); // border color
        $circle->setInteriorColor(array(1, 1, 0)); // inner color
        $circle->setContents("A cloudy circle annotation.");
        $circle->setTextLabel("John Dow"); // used as Author in a Reader application
        // style the border
        $borderStyle = $circle->getBorderStyle(true);
        $borderStyle->setWidth(2);
        // add a border effect
        $borderEffect = $circle->getBorderEffect(true);
        $borderEffect->setName(\SetaPDF_Core_Document_Page_Annotation_BorderEffect::CLOUDY);
        $borderEffect->setIntensity(5);
        // add to the page annotations object
        $annotations->add($circle);
        
        $document->save()->finish();