Rubber Stamp Annotation Class

Introduction

A rubber stamp annotation displays text or graphics intended to look as if they were stamped on the page with a rubber stamp. It is represented by the SetaPDF_Core_Document_Page_Annotation_Stamp class which also implements the  markup annotation class.

The PDF format specifies several icon names that shall be used in displaying the annotation. These icons are represented via class constants in SetaPDF too: 

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Icon name defined in PDF 32000-1:2008 - 12.5.6.12 Rubber Stamp Annotations

Methods

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

getIconName()

Get the icon name of the annotation.

setIconName()

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

Examples

Add Two Rubber Stamp Annotations

Add 2 stamp annotations without appearance (up to the reader application):

PHP
<?php
require_once('library/SetaPDF/Autoload.php');

$writer = new \SetaPDF_Core_Writer_Http('rubber-stamp-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 a rubber stamp annotation
$annotation = new \SetaPDF_Core_Document_Page_Annotation_Stamp(array(50, 680, 170, 760));
$annotations->add($annotation);

$annotation = new \SetaPDF_Core_Document_Page_Annotation_Stamp(
    array(50, 580, 170, 660),
    \SetaPDF_Core_Document_Page_Annotation_Stamp::ICON_APPROVED
);
$annotation->setPrintFlag(); // will be visible on print
$annotations->add($annotation);

$document->save()->finish();

Add Rubber Stamp Annotations With Individual Appearance

Add a single rubber stamp annotation with an individual appearance: 

PHP
<?php
require_once('library/SetaPDF/Autoload.php');

$writer = new \SetaPDF_Core_Writer_Http('rubber-stamp-annotation-with-image.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();

$width = 160;
$height = 80;

// create the annotation instance
$annotation = new \SetaPDF_Core_Document_Page_Annotation_Stamp(
    array(50, 580, 50 + $width, 580 + $height),
    uniqid('#', true)
);

// create an XObject which will represent the annotation appearance
$xObject = \SetaPDF_Core_XObject_Form::create($document, [0, 0, $width, $height]);
$canvas = $xObject->getCanvas();

// get an image instance
$image = \SetaPDF_Core_Image::getByPath('files/pdfs/tektown/Logo.png')->toXObject($document);

// Let's fit and center the image in the annotation area:
if ($image->getHeight($width) >= $height) {
    $image->draw(
        $canvas, $width / 2 - $image->getWidth($height) / 2, 0, null, $height
    );
} else {
    $image->draw(
        $canvas, 0, $height / 2 - $image->getHeight($width) / 2, $width
    );
}

// set the appearance
$annotation->setAppearance($xObject);

$annotation->setPrintFlag(); // will be visible on print
$annotations->add($annotation);

$document->save()->finish();