XObject Stamp

Introduction

The XObject stamp class allows you to create the stamp appearance absolutely individually by access its canvas object

Create an Instance

An instance could be created by passing an XObject to its constructor: 

PHP
// create a XObject
$xObject = \SetaPDF_Core_XObject_Form::create($document, array(0, 0, 200, 200));
// create a stamp instance
$xObjectStamp = new \SetaPDF_Stamper_Stamp_XObject($xObject);

Configure Properties

Beside the general stamp properties the xobject stamp class offers following properties that allow you to define its dimensions:  

getDimensions()

Get the stamp dimension.

getHeight()

Get the height of the XObject stamp.

getWidth()

Get the width of the XObject stamp.

setDimensions()

Set the dimensions of this stamp.

setHeight()

Set the individual height if the XObject stamp.

setWidth()

Set the individual width of the XObject stamp.

Example

PHP
<?php
/**
 * Create a transparent watermark on an existing document
 */

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

// create a writer
$writer = new \SetaPDF_Core_Writer_Http('smile.pdf', true);
// get a document instance
$document = \SetaPDF_Core_Document::loadByFilename(
    'files/pdfs/lenstown/Laboratory-Report.pdf', $writer
);

// create a stamper instance
$stamper = new \SetaPDF_Stamper($document);

// create a XObject
$xObject = \SetaPDF_Core_XObject_Form::create($document, array(0, 0, 205, 205));
// get the Canvas
$canvas = $xObject->getCanvas();
// Let's draw a smilie ;-)
$canvas
    ->setStrokingColor('#FF0000')
    ->setNonStrokingColor('#FFFF00')
    ->rotate(102.5, 102.5, 15)
    ->path()
    ->setLineWidth(5)
    ->draw()
    ->circle(102.5, 102.5, 100, \SetaPDF_Core_Canvas_Draw::STYLE_DRAW_AND_FILL) // head
    ->circle(60, 120, 15) // left eye
    ->circle(140, 120, 15) // right exe
    ->path()
    ->moveTo(50, 60)
    ->curveTo(60, 20, 145, 20, 155, 60) // mouth
    ->stroke();

// create the stamp object for the XObject
$xObjectStamp = new \SetaPDF_Stamper_Stamp_XObject($xObject);
$xObjectStamp->setOpacity(.5);

$stamper->addStamp($xObjectStamp, \SetaPDF_Stamper::POSITION_CENTER_MIDDLE);


// stamp the document with all added stamps of the stamper
$stamper->stamp();
// save the file and finish the writer (e.g. file handler will closed)
$document->save()->finish();