SetaPDF Demos

There seems to be a problem loading the components. Please check your PHP error logs for details!

Common issues could be that you missed to install the trial license or that you are using a trial version on an unsupported PHP version.

Artifact Stamp

A simple demo that shows you how to enclose the stamp content in a marked-content sequence to distinguish it from real content.

PHP
<?php

use com\setasign\SetaPDF\Demos\Stamper\Stamp\ArtifactTextStamp as ArtifactTextStamp;

// load and register the autoload function
require_once __DIR__ . '/../../../../../bootstrap.php';
require_once __DIR__ . '/../../../../../classes/Stamper/Stamp/ArtifactTextStamp.php';

// create a HTTP writer
$writer = new \SetaPDF_Core_Writer_Http('artifact.pdf', true);
//$writer = new \SetaPDF_Core_Writer_File('artifact.pdf');
// let's get the document
$document = \SetaPDF_Core_Document::loadByFilename(
    $assetsDirectory . '/pdfs/Brand-Guide.pdf',
    $writer
);

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

//--- Create a text stamp and wrap it in a Tagged stamp instance ---//

// create a font instance which is needed for the text stamp instance
$font = new \SetaPDF_Core_Font_TrueType_Subset(
    $document,
    $assetsDirectory . '/fonts/DejaVu/ttf/DejaVuSans.ttf'
);

// create a stamp instance
$textStamp = new ArtifactTextStamp($font, 10);
// set a text
$textStamp->setText('Personalized for John Dow (jon.dow@example.com)');

// add the stamp to the stamper instance
$stamper->addStamp($textStamp, [
    'position' => \SetaPDF_Stamper::POSITION_CENTER_TOP,
    'translateX' => 2,
    'translateY' => -2
]);

// execute the stamp process
$stamper->stamp();

// save and finish the document instance
$document->save()->finish();
PHP
<?php

namespace com\setasign\SetaPDF\Demos\Stamper\Stamp;

/**
 * Class ArtifactTextStamp
 */
class ArtifactTextStamp extends \SetaPDF_Stamper_Stamp_Text
{
    /**
     * @inheritDoc
     */
    protected function _preStamp(\SetaPDF_Core_Document $document, \SetaPDF_Core_Document_Page $page, array $stampData)
    {
        $page->getCanvas()
            ->markedContent()
            ->begin('Artifact');

        parent::_preStamp($document, $page, $stampData);
    }

    /**
     * @inheritDoc
     */
    protected function _postStamp(\SetaPDF_Core_Document $document, \SetaPDF_Core_Document_Page $page, array $stampData)
    {
        $quadPoints = parent::_postStamp($document, $page, $stampData);

        $page->getCanvas()
            ->markedContent()
            ->end();

        return $quadPoints;
    }
}