SetaPDF_Stamper_Stamp_Text The text stamp class

File: /SetaPDF/Stamper/Stamp/Text.php

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 SetaPDF_Core_Text_Block 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 font based on a TrueType font file
$font = SetaPDF_Core_Font_TrueType::create($document, 'path/to/font/file.ttf');
$stamp = new SetaPDF_Stamper_Stamp_Text($font, 16);

Class hierarchy

Summary

Properties

$_action

The currently attached action object

$_blendMode

protected string SetaPDF_Stamper_Stamp_Text::$_blendMode = 'Normal'

The blend mode

$_cacheCounter

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

$_dataCache

The cache data for the stamp

See

$_opacity

protected float SetaPDF_Stamper_Stamp_Text::$_opacity = 1.0

The opacity

$_opacityGs

protected array Array of SetaPDF_Core_Resource_ExtGState objects SetaPDF_Stamper_Stamp_Text::$_opacityGs = array()

Graphic state objects for handling transparency

$_optionalContentGroup

An optional content groups that should be used for the stamp

$_textBlock

$_visibility

protected string SetaPDF_Stamper_Stamp_Text::$_visibility = 'all'

The visibility property


Methods

__construct()

public SetaPDF_Stamper_Stamp_Text::__construct ( SetaPDF_Core_Font $font [, integer|float $fontSize = 12 ] )

The constructor.

Parameters
$font : SetaPDF_Core_Font

The font type of the text

$fontSize : integer|float

The font size of the text

_cacheStampData()

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

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

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
 

_postStamp()

protected array|null SetaPDF_Stamper_Stamp::_postStamp ( SetaPDF_Core_Document $document, SetaPDF_Core_Document_Page $page, array $stampData )

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

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

_preStamp()

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

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

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

_putAction()

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

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
 

_stamp()

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

Writes the text content of this stamp onto the canvas.

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

_stampByCache()

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

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 SetaPDF_Stamper_Exception

cleanUp()

public void SetaPDF_Stamper_Stamp_Text::cleanUp ( void )

Releases memory / cycled references.

getAction()

Get the current attached action.

getAlign()

public string SetaPDF_Stamper_Stamp_Text::getAlign ( void )

Get the text alignment.

Proxy method to SetaPDF_Core_Text_Block::getAlign() of the text block instance.

getBackgroundColor()

Get the background color object.

Proxy method to SetaPDF_Core_Text_Block::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 SetaPDF_Core_Text_Block::getBorderColor() of the text block instance.

getBorderWidth()

Get the border width.

Proxy method to SetaPDF_Core_Text_Block::getBorderWidth() of the text block instance.

getCharSpacing()

Get the character spacing value.

Proxy method to SetaPDF_Core_Text_Block::getCharSpacing() of the text block instance.

getDimensions()

public array SetaPDF_Stamper_Stamp::getDimensions ( void )

Get the stamp dimension.

getFont()

Get the current font object.

Proxy method to SetaPDF_Core_Text_Block::getFont() of the text block instance.

getFontSize()

public number SetaPDF_Stamper_Stamp_Text::getFontSize ( void )

Get the font size.

Proxy method to SetaPDF_Core_Text_Block::getFontSize() of the text block instance.

getHeight()

public number SetaPDF_Stamper_Stamp_Text::getHeight ( void )

Get the height of this stamp.

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

Proxy method to SetaPDF_Core_Text_Block::getHeight() of the text block instance.

See

getLineHeight()

Get the line height / leading.

Proxy method to SetaPDF_Core_Text_Block::getLineHeight() of the text block instance.

getOpacity()

public number SetaPDF_Stamper_Stamp::getOpacity ( void )

Get the opacity.

getOpacityBlendMode()

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 float|int SetaPDF_Stamper_Stamp::getOriginX ( SetaPDF_Core_Document_Page $page, string $position )

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 SetaPDF_Stamper::POSITION_XXX

getOriginY()

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

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 SetaPDF_Stamper::POSITION_XXX

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 SetaPDF_Core_Text_Block::getOutlineColor() of the text block instance.

See

getOutlineWidth()

Get the outline width.

The outline width is only used at specific rendering modes.

Proxy method to SetaPDF_Core_Text_Block::getOutlineWidth() of the text block instance.

getPaddingBottom()

Get the bottom padding.

Proxy method to SetaPDF_Core_Text_Block::getPaddingBottom() of the text block instance.

getPaddingLeft()

Get the left padding.

Proxy method to SetaPDF_Core_Text_Block::getPaddingLeft() of the text block instance.

getPaddingRight()

Get the right padding.

Proxy method to SetaPDF_Core_Text_Block::getPaddingRight() of the text block instance.

getPaddingTop()

Get the top padding.

Proxy method to SetaPDF_Core_Text_Block::getPaddingTop() of the text block instance.

getRenderingMode()

Get the defined rendering mode.

Proxy method to SetaPDF_Core_Text_Block::getRenderingMode() of the text block instance.

getText()

public string SetaPDF_Stamper_Stamp_Text::getText ( [ string $encoding = 'UTF-8' ] )

Get the text.

Proxy method to SetaPDF_Core_Text_Block::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 SetaPDF_Core_Text_Block::getTextColor() of the text block instance.

getVisibility()

public null|string SetaPDF_Stamper_Stamp::getVisibility ( void )

Get the visibility of the stamp object.

getWidth()

public number SetaPDF_Stamper_Stamp_Text::getWidth ( void )

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 SetaPDF_Core_Text_Block::getWidth() of the text block instance.

See

getWordSpacing()

Get the word spacing value.

Proxy method to SetaPDF_Core_Text_Block::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 void SetaPDF_Stamper_Stamp_Text::setAlign ( string $align )

Set the text alignment.

Proxy method to SetaPDF_Core_Text_Block::setAlign() of the text block instance.

Parameters
$align : string

The new align

setBackgroundColor()

Set the background color.

Proxy method to SetaPDF_Core_Text_Block::setBackgroundColor() of the text block instance.

Parameters
$color : SetaPDF_Core_DataStructure_Color|SetaPDF_Core_Type_Array|array|number|null

The new background color

See

setBorderColor()

Set the border color.

Proxy method to SetaPDF_Core_Text_Block::setBorderColor() of the text block instance.

Parameters
$color : SetaPDF_Core_DataStructure_Color|SetaPDF_Core_Type_Array|array|number|null

The new border color

See

setBorderWidth()

public void SetaPDF_Stamper_Stamp_Text::setBorderWidth ( float|integer $borderWidth )

Set the border width.

Proxy method to SetaPDF_Core_Text_Block::setBorderWidth() of the text block instance.

Parameters
$borderWidth : float|integer

The new border width

setCharSpacing()

public void SetaPDF_Stamper_Stamp_Text::setCharSpacing ( number $charSpacing )

Set the character spacing value.

Proxy method to SetaPDF_Core_Text_Block::setCharSpacing() of the text block instance.

Parameters
$charSpacing : number

The new char spacing

setFont()

public void SetaPDF_Stamper_Stamp_Text::setFont ( SetaPDF_Core_Font $font [, null|number $fontSize = null ] )

Set the font object and size.

Proxy method to SetaPDF_Core_Text_Block::setFont() of the text block instance.

Parameters
$font : SetaPDF_Core_Font

The new font type

$fontSize : null|number

The new font size

setFontSize()

public void SetaPDF_Stamper_Stamp_Text::setFontSize ( number $fontSize )

Set the font size.

Proxy method to SetaPDF_Core_Text_Block::setFontSize() of the text block instance.

Parameters
$fontSize : number

The new font size

setLineHeight()

public void SetaPDF_Stamper_Stamp_Text::setLineHeight ( float|integer|null $lineHeight )

Set the line height / leading.

Proxy method to SetaPDF_Core_Text_Block::setLineHeight() of the text block instance.

Parameters
$lineHeight : float|integer|null

The new line height

setLink()

public void SetaPDF_Stamper_Stamp::setLink ( string $uri )

Set a link onto the stamp.

Parameters
$uri : string

The link

See

setOpacity()

public void SetaPDF_Stamper_Stamp::setOpacity ( float $alpha [, string $blendMode = 'Normal' ] )

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|null
 

setOutlineColor()

Set the texts outline color.

Only used with a specific text rendering mode.

Proxy method to SetaPDF_Core_Text_Block::setOutlineColor() of the text block instance.

Parameters
$color : SetaPDF_Core_DataStructure_Color|SetaPDF_Core_Type_Array|array|number

The new outline color

See

setOutlineWidth()

public void SetaPDF_Stamper_Stamp_Text::setOutlineWidth ( float $outlineWidth )

Set the outline width.

The outline width is only used at specific rendering modes.

Proxy method to SetaPDF_Core_Text_Block::setOutlineWidth() of the text block instance.

Parameters
$outlineWidth : float

The new outline width.

setPadding()

public void SetaPDF_Stamper_Stamp_Text::setPadding ( number $padding )

Set the padding.

Proxy method to SetaPDF_Core_Text_Block::setPadding() of the text block instance.

Parameters
$padding : number

The new padding

setPaddingBottom()

public void SetaPDF_Stamper_Stamp_Text::setPaddingBottom ( number $paddingBottom )

Set the bottom padding.

Proxy method to SetaPDF_Core_Text_Block::setPaddingBottom() of the text block instance.

Parameters
$paddingBottom : number

The new padding bottom

setPaddingLeft()

public void SetaPDF_Stamper_Stamp_Text::setPaddingLeft ( number $paddingLeft )

Set the left padding.

Proxy method to SetaPDF_Core_Text_Block::setPaddingLeft() of the text block instance.

Parameters
$paddingLeft : number

The new padding left

setPaddingRight()

public void SetaPDF_Stamper_Stamp_Text::setPaddingRight ( number $paddingRight )

Set the right padding.

Proxy method to SetaPDF_Core_Text_Block::setPaddingRight() instance.

Parameters
$paddingRight : number

The new padding right

setPaddingTop()

public void SetaPDF_Stamper_Stamp_Text::setPaddingTop ( number $paddingTop )

Set the top padding.

Proxy method to SetaPDF_Core_Text_Block::setPaddingTop() of the text block instance.

Parameters
$paddingTop : number

The new padding top

setRenderingMode()

public void SetaPDF_Stamper_Stamp_Text::setRenderingMode ( [ integer $renderingMode = 0 ] )

Set the rendering mode.

Proxy method to SetaPDF_Core_Text_Block::setRenderingMode() of the text block instance.

Parameters
$renderingMode : integer

The new rendering mode

See

setText()

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

Set the text.

Proxy method to SetaPDF_Core_Text_Block::setText() of the text block instance.

Parameters
$text : string

The new text

$encoding : string

The encoding of the text

setTextColor()

setVisibility()

public void SetaPDF_Stamper_Stamp::setVisibility ( null|string $visibility )

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 : null|string

Use the constants VISIBILITY_XXX or null(equal to VISIBILITY_ALL)

Exceptions

Throws InvalidArgumentException

setWidth()

public void SetaPDF_Stamper_Stamp_Text::setWidth ( float|integer $width )

Set the width of the stamp.

Padding is NOT included in the $width parameter.

Proxy method to SetaPDF_Core_Text_Block::setWidth() of the text block instance.

Parameters
$width : float|integer

The new width

setWordSpacing()

public void SetaPDF_Stamper_Stamp_Text::setWordSpacing ( number $wordSpacing )

Set the word spacing value.

Proxy method to SetaPDF_Core_Text_Block::setWordSpacing() of the text block instance.

Parameters
$wordSpacing : number

The new word spacing

stamp()

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

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

updateCacheCounter()

Updates the cache counter.