setasign\SetaPDF2\Stamper\Stamp

TextStamp The text stamp class

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

With the text stamp class you can add dynamic text to an existing PDF document. The text can be of multiple lines and will break automatically if a width is defined.

Internally the class uses a \setasign\SetaPDF2\Core\Text\TextBlock object.

The text stamp class has to be initiated with a font instance. The SetaPDF core system actually offers all standard PDF fonts and a parser for TrueType font-files:

// create a standard font
$font = \SetaPDF_Core_Font_Standard_Helvetica::create($document);
$stamp = new \SetaPDF_Stamper_Stamp_Text($font, 16);

// or create a subset font based on a TrueType font file
$font = new \SetaPDF_Core_Font_TrueType_Subset($document, 'path/to/font/file.ttf');
$stamp = new \SetaPDF_Stamper_Stamp_Text($font, 16);

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

$_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

$_textBlock

A text block instance

$_visibility

protected string AbstractStamp::$_visibility = 'all'

The visibility property


Methods

__construct()

public TextStamp::__construct (
\SetaPDF_Core_Font_FontInterface $font,
int|float $fontSize = 12
)

The constructor.

Parameters
$font : \SetaPDF_Core_Font_FontInterface

The font type of the text

$fontSize : int|float

The font size of the text

_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 TextStamp::_stamp (
\SetaPDF_Core_Document $document,
\SetaPDF_Core_Document_Page $page,
array $stampData
): bool

Writes the text content of this stamp onto the canvas.

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

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Font\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\NotImplementedException

_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 TextStamp::cleanUp (
void
): void

Releases memory / cycled references.

getAction()

Get the current attached action.

getAlign()

public TextStamp::getAlign (
void
): string

Get the text alignment.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getAlign() of the text block instance.

getBackgroundColor()

Get the background color object.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getBackgroundColor() of the text block instance.

getBorderColor()

Get the border color object.

If no border color is defined the a greyscale black color will be returned.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getBorderColor() of the text block instance.

getBorderWidth()

public TextStamp::getBorderWidth (
void
): number

Get the border width.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getBorderWidth() of the text block instance.

getCharSpacing()

public TextStamp::getCharSpacing (
void
): number

Get the character spacing value.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getCharSpacing() of the text block instance.

getDimensions()

public AbstractStamp::getDimensions (
void
): array

Get the stamp dimension.

getFont()

Get the current font object.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getFont() of the text block instance.

getFontSize()

public TextStamp::getFontSize (
void
): number

Get the font size.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getFontSize() of the text block instance.

getHeight()

public TextStamp::getHeight (
void
): number

Get the height of this stamp.

Calculation is done by number of lines, line-height and top and bottom padding values.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getHeight() of the text block instance.

See

getLineHeight()

public TextStamp::getLineHeight (
void
): number

Get the line height / leading.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getLineHeight() of the text block instance.

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

getOutlineColor()

Get the texts outline color object.

If no outline color is defined the a greyscale black color will be returned. The outline color is only used at specific rendering modes.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getOutlineColor() of the text block instance.

See

getOutlineWidth()

public TextStamp::getOutlineWidth (
void
): float

Get the outline width.

The outline width is only used at specific rendering modes.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getOutlineWidth() of the text block instance.

getPaddingBottom()

public TextStamp::getPaddingBottom (
void
): number

Get the bottom padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getPaddingBottom() of the text block instance.

getPaddingLeft()

public TextStamp::getPaddingLeft (
void
): number

Get the left padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getPaddingLeft() of the text block instance.

getPaddingRight()

public TextStamp::getPaddingRight (
void
): number

Get the right padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getPaddingRight() of the text block instance.

getPaddingTop()

public TextStamp::getPaddingTop (
void
): number

Get the top padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getPaddingTop() of the text block instance.

getRenderingMode()

public TextStamp::getRenderingMode (
void
): number

Get the defined rendering mode.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getRenderingMode() of the text block instance.

getText()

public TextStamp::getText (
string $encoding = 'UTF-8'
): string

Get the text.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getText() of the text block instance.

Parameters
$encoding : string

The encoding of the text

getTextBlock()

Get the text block of this stamp.

getTextColor()

Get the text color object.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getTextColor() of the text block instance.

getUnderline()

public TextStamp::getUnderline (
void
): bool

Gets whether to draw an underline or not.

Proxy method to {@Link \setasign\SetaPDF2\Core\Text\TextBlock::getUnderline()} of the text block instance.

getUnderlineColor()

Get the underline color object.

Proxy method to {@Link \setasign\SetaPDF2\Core\Text\TextBlock::getUnderlineColor()} of the text block instance.

getVisibility()

public AbstractStamp::getVisibility (
void
): ?string

Get the visibility of the stamp object.

getWidth()

public TextStamp::getWidth (
void
): number

Get the width of the stamp object.

This method returns the complete width of the stamp object.

The value set in setWidth() may be differ to the one returned by this method because of padding values.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getWidth() of the text block instance.

See

getWordSpacing()

public TextStamp::getWordSpacing (
void
): number

Get the word spacing value.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::getWordSpacing() of the text block instance.

setAction()

Add an action object to the stamp object.

Parameters
$action : \SetaPDF_Core_Document_Action

The action object

setAlign()

public TextStamp::setAlign (
string $align
): void

Set the text alignment.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setAlign() of the text block instance.

Parameters
$align : string

The new align

setBackgroundColor()

public TextStamp::setBackgroundColor (
\SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null $color
): void

Set the background color.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setBackgroundColor() of the text block instance.

Parameters
$color : \SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null

The new background color

See

setBorderColor()

public TextStamp::setBorderColor (
\SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null $color
): void

Set the border color.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setBorderColor() of the text block instance.

Parameters
$color : \SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null

The new border color

See

setBorderWidth()

public TextStamp::setBorderWidth (
float|int $borderWidth
): void

Set the border width.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setBorderWidth() of the text block instance.

Parameters
$borderWidth : float|int

The new border width

setCharSpacing()

public TextStamp::setCharSpacing (
number $charSpacing
): void

Set the character spacing value.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setCharSpacing() of the text block instance.

Parameters
$charSpacing : number

The new char spacing

setFont()

public TextStamp::setFont (
\SetaPDF_Core_Font_FontInterface $font,
?number $fontSize = null
): void

Set the font object and size.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setFont() of the text block instance.

Parameters
$font : \SetaPDF_Core_Font_FontInterface

The new font type

$fontSize : ?number

The new font size

setFontSize()

public TextStamp::setFontSize (
number $fontSize
): void

Set the font size.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setFontSize() of the text block instance.

Parameters
$fontSize : number

The new font size

setLineHeight()

public TextStamp::setLineHeight (
float|int|null $lineHeight
): void

Set the line height / leading.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setLineHeight() of the text block instance.

Parameters
$lineHeight : float|int|null

The new line 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
 

setOutlineColor()

public TextStamp::setOutlineColor (
\SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null $color
): void

Set the texts outline color.

Only used with a specific text rendering mode.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setOutlineColor() of the text block instance.

Parameters
$color : \SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null

The new outline color

See

setOutlineWidth()

public TextStamp::setOutlineWidth (
float $outlineWidth
): void

Set the outline width.

The outline width is only used at specific rendering modes.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setOutlineWidth() of the text block instance.

Parameters
$outlineWidth : float

The new outline width.

setPadding()

public TextStamp::setPadding (
number $padding
): void

Set the padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setPadding() of the text block instance.

Parameters
$padding : number

The new padding

setPaddingBottom()

public TextStamp::setPaddingBottom (
number $paddingBottom
): void

Set the bottom padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setPaddingBottom() of the text block instance.

Parameters
$paddingBottom : number

The new padding bottom

setPaddingLeft()

public TextStamp::setPaddingLeft (
number $paddingLeft
): void

Set the left padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setPaddingLeft() of the text block instance.

Parameters
$paddingLeft : number

The new padding left

setPaddingRight()

public TextStamp::setPaddingRight (
number $paddingRight
): void

Set the right padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setPaddingRight() instance.

Parameters
$paddingRight : number

The new padding right

setPaddingTop()

public TextStamp::setPaddingTop (
number $paddingTop
): void

Set the top padding.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setPaddingTop() of the text block instance.

Parameters
$paddingTop : number

The new padding top

setRenderingMode()

public TextStamp::setRenderingMode (
int $renderingMode = 0
): void

Set the rendering mode.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setRenderingMode() of the text block instance.

Parameters
$renderingMode : int

The new rendering mode

See

setText()

public TextStamp::setText (
string $text,
string $encoding = 'UTF-8'
): void

Set the text.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setText() of the text block instance.

Parameters
$text : string

The new text

$encoding : string

The encoding of the text

setTextColor()

public TextStamp::setTextColor (
\SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null $color
): void

Set the text color.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setTextColor() of the text block instance.

Parameters
$color : \SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null

The new text color

See

setTextWidth()

public TextStamp::setTextWidth (
float|int $width
): void

Set the width of the text of the stamp.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setTextWidth() of the text block instance.

Parameters
$width : float|int

The new width

setUnderline()

public TextStamp::setUnderline (
bool $underline
): void

Set whether to draw an underline or not.

Proxy method to {@Link \setasign\SetaPDF2\Core\Text\TextBlock::setUnderline()} of the text block instance.

Parameters
$underline : bool
 

setUnderlineColor()

public TextStamp::setUnderlineColor (
\SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null $color
): void

Set the underline color.

Proxy method to {@Link \setasign\SetaPDF2\Core\Text\TextBlock::setUnderlineColor()} of the text block instance.

Parameters
$color : \SetaPDF_Core_DataStructure_Color|int|float|string|array|\SetaPDF_Core_Type_Array|null

The new underline color

See

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()

WARNING: This method is marked as deprecated!

Use setTextWidth() instead.

public TextStamp::setWidth (
int|float $width
): void
Parameters
$width : int|float
 
See

setWordSpacing()

public TextStamp::setWordSpacing (
number $wordSpacing
): void

Set the word spacing value.

Proxy method to \setasign\SetaPDF2\Core\Text\TextBlock::setWordSpacing() of the text block instance.

Parameters
$wordSpacing : number

The new word spacing

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.