SetaPDF Demos

Rotation

This demo shows the rotation behavior of stamp objects. The rotation is done so that the stamp appearance is completely visible throughout.

PHP
<?php

// load and register the autoload function
require_once __DIR__ . '/../../../../../bootstrap.php';

$rotationOptions = require 'options.php';

$value = displaySelect('Position & Rotation:', $rotationOptions);
$data = $rotationOptions[$value];

$writer = new SetaPDF_Core_Writer_Http('positioning-and-translate.pdf', true);
$document = new SetaPDF_Core_Document($writer);
// let's add 2 pages for demonstration purpose
$pages = $document->getCatalog()->getPages();
$pages->create(SetaPDF_Core_PageFormats::A4, SetaPDF_Core_PageFormats::ORIENTATION_PORTRAIT);
$pages->create(SetaPDF_Core_PageFormats::A4, SetaPDF_Core_PageFormats::ORIENTATION_LANDSCAPE);

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

// 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
$stamp = new SetaPDF_Stamper_Stamp_Text($font, 12);
$stamp->setBackgroundColor([0.5, 1, 1]);
$stamp->setBorderWidth(1);
$stamp->setPadding(2);
$stamp->setWidth(180);
$stamp->setAlign(SetaPDF_Core_Text::ALIGN_CENTER);
$stamp->setText('A simple example text to demonstrate rotation.');

// add the stamp object on all pages on the given position
$stamper->addStamp(
    $stamp,
    [
        'position' => $data['position'],
        'rotation' => $data['rotation']
    ]
);

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

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

return [
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_LEFT_TOP & 45°',
        'position' => SetaPDF_Stamper::POSITION_LEFT_TOP,
        'rotation' => 45
    ],
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_LEFT_TOP & -45°',
        'position' => SetaPDF_Stamper::POSITION_RIGHT_TOP,
        'rotation' => -45
    ],
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_CENTER_TOP & 180°',
        'position' => SetaPDF_Stamper::POSITION_CENTER_TOP,
        'rotation' => 180
    ],
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_LEFT_MIDDLE & 90°',
        'position' => SetaPDF_Stamper::POSITION_LEFT_MIDDLE,
        'rotation' => 90
    ],
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_CENTER_MIDDLE & 25°',
        'position' => SetaPDF_Stamper::POSITION_CENTER_MIDDLE,
        'rotation' => 25
    ],
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_RIGHT_MIDDLE & -90°',
        'position' => SetaPDF_Stamper::POSITION_RIGHT_MIDDLE,
        'rotation' => -90
    ],

    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_LEFT_BOTTOM & 45°',
        'position' => SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
        'rotation' => 45
    ],
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_RIGHT_BOTTOM & -45°',
        'position' => SetaPDF_Stamper::POSITION_RIGHT_BOTTOM,
        'rotation' => -45
    ],
    [
        'displayValue' => 'SetaPDF_Stamper::POSITION_CENTER_BOTTOM & 180°',
        'position' => SetaPDF_Stamper::POSITION_CENTER_BOTTOM,
        'rotation' => 180
    ],
];