PDF Stamp

Introduction

The PDF stamp class allows you to use a page of an existing PDF document as a stamp appearance.

It's only the pages content stream that will be transformed into a reusable structure. By doing this, content types like links, form fields or other kind of page annotations will loose their relation and will not be available in the final stamp appearance.

Create an Instance

An instance could be created by passing a filename or a document instance, a page number and a boundary box to its constructor: 

PHP
$stamp = new \SetaPDF_Stamper_Stamp_Pdf(
    'path/to/stamp.pdf', 1, \SetaPDF_Core_PageBoundaries::CROP_BOX
);

// or

$document = \SetaPDF_Core_Document::loadByFilename('path/to/stamp.pdf');
$stamp = new \SetaPDF_Stamper_Stamp_Pdf(
    $document, 1, \SetaPDF_Core_PageBoundaries::CROP_BOX
);

Configure Properties

Beside the general stamp properties the PDF stamp class offers following stamp properties: 

Source Document Specific

Following methods are available to control which page and boundary box should be used from the initial document instance: 

getBoundaryBox()

Get the current boundary box name.

getPageNumber()

Get the page number of the page that should be used for the stamp appearance.

setBoundaryBox()

Set the boundary box of the imported page.

setPageNumber()

Set the page number for the page which should be used for the stamp appearance.

Dimensions

getHeight()

Get the height of the pdf page stamp.

getWidth()

Get the width of the pdf page stamp.

setHeight()

Set the individual height if the pdf page stamp.

setWidth()

Set the individual width of the pdf page stamp.

Example

The example simply uses the first page of this document as the stamp appearance: 

PHP
<?php
/**
 * Adds an imported page (a vector logo) on the top left position for all pages
 */

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

// create a writer
$writer = new \SetaPDF_Core_Writer_Http('image.pdf', true);
// get a document instance
$document = \SetaPDF_Core_Document::loadByFilename(
    'files/pdfs/Fact-Sheet-without-personalization.pdf', $writer
);

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

// initiate the stamp
$stamp = new \SetaPDF_Stamper_Stamp_Pdf(
    'files/pdfs/camtown/Logo.pdf',
    1,
    \SetaPDF_Core_PageBoundaries::ART_BOX
);
// set height (and width until no setWidth is set the ratio will retain)
$stamp->setHeight(23);

// add stamp to stamper on position left top for all pages with a specific translation
$stamper->addStamp($stamp, array(
    'translateX' => 43,
    'translateY' => -38
));

// stamp the document
$stamper->stamp();

// save and send it to the client
$document->save()->finish();