PHP
<?php
use setasign\SetaPDF2\Core\Document;
use setasign\SetaPDF2\Core\Document\Page\Annotation;
use setasign\SetaPDF2\Core\PageFormats;
use setasign\SetaPDF2\Core\Writer\HttpWriter;
require_once('library/SetaPDF/Autoload.php');
$writer = new HttpWriter('square-and-circle-annotation.pdf', true);
$document = new Document($writer);
// let's create a page
$pages = $document->getCatalog()->getPages();
$page = $pages->create(PageFormats::A4);
// get access to the annotations helper
$annotations = $page->getAnnotations();
// create a new square annotation
$square = new Annotation\SquareAnnotation([50, 700, 150, 750]);
$square->setColor([1, 0, 0]); // border color
$square->setInteriorColor([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(Annotation\BorderStyle::DASHED);
// add to the page annotations object
$annotations->add($square);
// create a new circle annotation
$circle = new Annotation\CircleAnnotation([200, 700, 300, 750]);
$circle->setColor([0, 0, 1]); // border color
$circle->setInteriorColor([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(Annotation\BorderStyle::BEVELED);
// add to the page annotations object
$annotations->add($circle);
// create another new square annotation
$square = new Annotation\SquareAnnotation([50, 600, 150, 650]);
$square->setColor([0, 1, 0]); // border color
$square->setInteriorColor([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(Annotation\BorderEffect::CLOUDY);
$borderEffect->setIntensity(5);
// add to the page annotations object
$annotations->add($square);
// create another new circle annotation
$circle = new Annotation\CircleAnnotation([200, 600, 300, 650]);
$circle->setColor([0, 1, 1]); // border color
$circle->setInteriorColor([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(Annotation\BorderEffect::CLOUDY);
$borderEffect->setIntensity(5);
// add to the page annotations object
$annotations->add($circle);
$document->save()->finish();