setasign\SetaPDF2\Stamper\Stamp

XObjectStamp The XObject stamp class

File: /SetaPDF v2/Stamper/Stamp/XObjectStamp.php
Old class name (alias): \SetaPDF_Stamper_Stamp_XObject

This stamp class is able to use a \setasign\SetaPDF2\Core\XObject\XObject instance as its stamp appearance. XObjects could be images or so called form XObjects.

A form XObject is a PDF content stream that is a self-contained description of any sequence of graphics objects (including path objects, text objects and sampled images).

This stamp class allows you to stamp separately form XObjects or image XObjects. A form XObject could include for example drawing operations:

// Create a form XObject with the dimensions of 100 x 100
$xObject = \SetaPDF_Core_XObject_Form::create($document, array(0, 0, 100, 100));
$canvas = $xObject->getCanvas();
$canvas->path()->setLineWidth(1);
$canvas->draw()
    ->rect(0, 0, 100, 100) // Draw a rectangle into the form XObject
    ->circle(50, 50, 50); // Draw a circle into the form XObject

$stamp = new \SetaPDF_Stamper_Stamp_XObject($xObject);

Class hierarchy

Summary

Constants

VISIBILITY_ALL

public const string AbstractStamp::VISIBILITY_ALL = 'all'

Visibility constant

VISIBILITY_PRINT

public const string AbstractStamp::VISIBILITY_PRINT = 'print'

Visibility constant

VISIBILITY_VIEW

public const string AbstractStamp::VISIBILITY_VIEW = 'view'

Visibility constant


Properties

$_action

The currently attached action object

$_blendMode

protected string AbstractStamp::$_blendMode = 'Normal'

The blend mode

$_cacheCounter

protected int AbstractStamp::$_cacheCounter = 0

An internal used id for forcing a recreation if a property was changed

$_dataCache

protected array AbstractStamp::$_dataCache

The cache data for the stamp

See

$_height

protected float|int XObjectStamp::$_height

The individual height of the image

$_opacity

protected float AbstractStamp::$_opacity = 1.0

The opacity

$_opacityGs

protected array AbstractStamp::$_opacityGs = array()

Graphic state objects for handling transparency

Array of \setasign\SetaPDF2\Core\Resource\ExtGState objects

$_optionalContentGroup

An optional content groups that should be used for the stamp

$_visibility

protected string AbstractStamp::$_visibility = 'all'

The visibility property

$_width

protected float|int XObjectStamp::$_width

The individual width of the image

$_xObject

The XObject instance


Methods

__construct()

The constructor.

Parameters
$xObject : \SetaPDF_Core_XObject

The xobject instance

_cacheStampData()

protected AbstractStamp::_cacheStampData (
string $cacheKey,
string $stream,
array $quadPoints
): void

Caches a content stream part.

Parameters
$cacheKey : string
 
$stream : string
 
$quadPoints : array
 

_ensureResources()

Ensures that all stamp resources are added to the page.

This is needed to reuse a cached stamp stream.

Parameters
$document : \SetaPDF_Core_Document
 
$page : \SetaPDF_Core_Document_Page
 
Return Values

An array of resource names

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

See

_getOpacityGraphicState()

Get and caches opacity graphic states.

Parameters
$document : \SetaPDF_Core_Document
 
$opacity : float
 

_getVisibilityGroup()

Get and adds the visibility group of this stamp to a document.

Parameters
$document : \SetaPDF_Core_Document
 
Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

_postStamp()

protected AbstractStamp::_postStamp (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Document_Page $page,
array $stampData
): ?array

Method which is called after the main stamp method is executed.

Parameters
$document : \SetaPDF_Core_Document
 
$page : \SetaPDF_Core_Document_Page
 
$stampData : array
 
Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

_preStamp()

protected AbstractStamp::_preStamp (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Document_Page $page,
array $stampData
): void

Method which is called before the main stamp method is executed.

Parameters
$document : \SetaPDF_Core_Document
 
$page : \SetaPDF_Core_Document_Page
 
$stampData : array
 
Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

_putAction()

protected AbstractStamp::_putAction (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Document_Page $page,
array $stampData,
number $xy1,
number $xy2,
number $xy3,
number $xy4
): void

Put the action via an link annotation above the stamp object.

Parameters
$document : \SetaPDF_Core_Document
 
$page : \SetaPDF_Core_Document_Page
 
$stampData : array
 
$xy1 : number
 
$xy2 : number
 
$xy3 : number
 
$xy4 : number
 
Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

_stamp()

protected XObjectStamp::_stamp (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Document_Page $page,
array $stampData
): bool

Writes the xobject draw operators of this stamp onto the canvas.

Parameters
$document : \SetaPDF_Core_Document
 
$page : \SetaPDF_Core_Document_Page
 
$stampData : array
 

_stampByCache()

protected AbstractStamp::_stampByCache (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Document_Page $page,
array $stampData
): true|string

Try to stamp with the page with a cached content stream part.

Parameters
$document : \SetaPDF_Core_Document
 
$page : \SetaPDF_Core_Document_Page
 
$stampData : array
 
Return Values

True if the stamp was written by a cache object, a cache key if it was not found

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Stamper\Exception

cleanUp()

public XObjectStamp::cleanUp (
void
): void

Release resources / cycled references.

getAction()

Get the current attached action.

getDimensions()

public AbstractStamp::getDimensions (
void
): array

Get the stamp dimension.

getHeight()

public XObjectStamp::getHeight (
void
): float|int

Get the height of the XObject stamp.

If no individual height is given the height will be received from the XObject object by forwarding an individual width (if available) to keep the aspect ratio.

getOpacity()

public AbstractStamp::getOpacity (
void
): float

Get the opacity.

getOpacityBlendMode()

public AbstractStamp::getOpacityBlendMode (
void
): string

Get the blend mode.

See
  • PDF 32000-1:2008 - 11.3.5, "Blend Mode"

getOptionalContentGroup()

Get the optional content group for this stamp.

getOriginX()

public AbstractStamp::getOriginX (
\SetaPDF_Core_Document_Page $page,
string $position
): float|int

Get the x-origin in view to the position of the stamp object.

Parameters
$page : \SetaPDF_Core_Document_Page

The page instance

$position : string

Position constant \setasign\SetaPDF2\Stamper\Stamper::POSITION_XXX

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

getOriginY()

public AbstractStamp::getOriginY (
\SetaPDF_Core_Document_Page $page,
string $position
): float|int

Get the y-origin in view to the position of the stamp object.

Parameters
$page : \SetaPDF_Core_Document_Page

The page instance

$position : string

Position constant \setasign\SetaPDF2\Stamper\Stamper::POSITION_XXX

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

getVisibility()

public AbstractStamp::getVisibility (
void
): ?string

Get the visibility of the stamp object.

getWidth()

public XObjectStamp::getWidth (
void
): float|int

Get the width of the XObject stamp.

If no individual width is given the width will be received from the XObject object by forwarding an individual height (if available) to keep the aspect ratio.

getXObject()

Get the XObject instance.

setAction()

Add an action object to the stamp object.

Parameters
$action : \SetaPDF_Core_Document_Action

The action object

setDimensions()

public XObjectStamp::setDimensions (
float|int $width,
float|int $height
): void

Set the dimensions of this stamp.

Parameters
$width : float|int

The new width

$height : float|int

The new height

setHeight()

public XObjectStamp::setHeight (
float|int $height
): void

Set the individual height if the XObject stamp.

Parameters
$height : float|int

The new height

setLink()

public AbstractStamp::setLink (
string $uri
): void

Set a link onto the stamp.

Parameters
$uri : string

The link

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

See

setOpacity()

public AbstractStamp::setOpacity (
float $alpha,
string $blendMode = 'Normal'
): void

Set the opacity and blend mode of the stamp object.

Parameters
$alpha : float

A value between 0 and 1, whereas 1 is defined as 100% opacity

$blendMode : string

A blend mode defined in PDF 32000-1:2008 - 11.3.5, "Blend Mode"

Exceptions

Throws \InvalidArgumentException

setOptionalContentGroup()

Set the optional content group for this stamp.

Parameters
$optionalContentGroup : ?\SetaPDF_Core_Document_OptionalContent_Group
 

setVisibility()

public AbstractStamp::setVisibility (
?string $visibility
): void

Set the visibility of the stamp object.

This method controls the visibility of the stamp object on screen view and/or printer output.

Parameters
$visibility : ?string

Use the constants VISIBILITY_XXX or null(equal to VISIBILITY_ALL)

Exceptions

Throws \InvalidArgumentException

setWidth()

public XObjectStamp::setWidth (
float|int $width
): void

Set the individual width of the XObject stamp.

Parameters
$width : float|int

The new width

setXObject()

public XObjectStamp::setXObject (): void

Set the XObject.

Parameters
$xObject : \SetaPDF_Core_XObject

The new xobject instance

stamp()

public AbstractStamp::stamp (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Document_Page $page,
array $stampData
): bool

Stamp this stamp object onto a page.

Parameters
$document : \SetaPDF_Core_Document

The document object

$page : \SetaPDF_Core_Document_Page

The page object

$stampData : array

The stampData array

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Stamper\Exception

updateCacheCounter()

public AbstractStamp::updateCacheCounter (
void
): void

Updates the cache counter.