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 \setasign\SetaPDF2\Core\Document\Page\Annotation\StampAnnotation 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):

Note, that the viewer application has to render the appearance. This is not supported by all PDF viewers.

PHP
<?php

use setasign\SetaPDF2\Core\Document;
use setasign\SetaPDF2\Core\Document\Page\Annotation\StampAnnotation;
use setasign\SetaPDF2\Core\PageFormats;
use setasign\SetaPDF2\Core\Writer\HttpWriter;

require_once('library/SetaPDF/Autoload.php');

$writer = new HttpWriter('rubber-stamp-annotation.pdf', true);
$document = new Document($writer);

// let's create a page
$pages = $document->getCatalog()->getPages();
$page = $pages->create(PageFormats::A4);

$annotations = $page->getAnnotations();

// create a rubber stamp annotation
$annotation = new StampAnnotation([50, 680, 170, 760]);
$annotations->add($annotation);

$annotation = new StampAnnotation(
    [50, 580, 170, 660],
    StampAnnotation::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

use setasign\SetaPDF2\Core\Document;
use setasign\SetaPDF2\Core\Document\Page\Annotation\StampAnnotation;
use setasign\SetaPDF2\Core\Image\Image;
use setasign\SetaPDF2\Core\PageFormats;
use setasign\SetaPDF2\Core\Writer\HttpWriter;
use setasign\SetaPDF2\Core\XObject\Form as FormXObject;

require_once('library/SetaPDF/Autoload.php');

$writer = new HttpWriter('rubber-stamp-annotation-with-image.pdf', true);
$document = new Document($writer);

// let's create a page
$pages = $document->getCatalog()->getPages();
$page = $pages->create(PageFormats::A4);

$annotations = $page->getAnnotations();

$width = 160;
$height = 80;

// create the annotation instance
$annotation = new StampAnnotation(
    [50, 580, 50 + $width, 580 + $height],
    uniqid('#', true)
);

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

// get an image instance
$image = 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();