SetaPDF_Stamper_Stamp_RichText The rich-text stamp class

File: /SetaPDF v2/Stamper/Stamp/RichText.php

With the stamp class you can add rich-text to an existing PDF document.

The text can be created by a subset of HTML and CSS style attributes.

Internally the class uses a SetaPDF_Core_Text_RichTextBlock object. Most methods of this class are proxy methods to the RichTextBlock instance.

Class hierarchy

Summary

Constants

VISIBILITY_ALL

public const string SetaPDF_Stamper_Stamp::VISIBILITY_ALL = 'all'

Visibility constant

VISIBILITY_PRINT

public const string SetaPDF_Stamper_Stamp::VISIBILITY_PRINT = 'print'

Visibility constant

VISIBILITY_VIEW

public const string SetaPDF_Stamper_Stamp::VISIBILITY_VIEW = 'view'

Visibility constant


Properties

$_action

The currently attached action object

$_blendMode

protected string SetaPDF_Stamper_Stamp::$_blendMode = 'Normal'

The blend mode

$_cacheCounter

protected integer SetaPDF_Stamper_Stamp::$_cacheCounter = 0

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

$_dataCache

The cache data for the stamp

See

$_fonts

protected array SetaPDF_Stamper_Stamp_RichText::$_fonts = array()

An array holding font references

$_opacity

protected float SetaPDF_Stamper_Stamp::$_opacity = 1.0

The opacity

$_opacityGs

protected array SetaPDF_Stamper_Stamp::$_opacityGs = array()

Graphic state objects for handling transparency

Array of SetaPDF_Core_Resource_ExtGState objects

$_optionalContentGroup

An optional content groups that should be used for the stamp

$_richTextBlock

$_text

protected string SetaPDF_Stamper_Stamp_RichText::$_text = ''

$_visibility

protected string SetaPDF_Stamper_Stamp::$_visibility = 'all'

The visibility property


Methods

__construct()

public SetaPDF_Stamper_Stamp_RichText::__construct (
SetaPDF_Core_Document $document [, callable $fontLoader = null ]
)

The constructor.

Parameters
$document : SetaPDF_Core_Document
 
$fontLoader : callable
 

_cacheStampData()

protected SetaPDF_Stamper_Stamp::_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 SetaPDF_Core_SecHandler_Exception

Throws SetaPDF_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 SetaPDF_Core_SecHandler_Exception

Throws SetaPDF_Core_Type_Exception

_postStamp()

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

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 SetaPDF_Core_Type_Exception

_preStamp()

protected SetaPDF_Stamper_Stamp::_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 SetaPDF_Core_SecHandler_Exception

Throws SetaPDF_Core_Type_Exception

_putAction()

protected SetaPDF_Stamper_Stamp::_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 SetaPDF_Core_Type_Exception

_stamp()

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

Writes the content of this stamp onto the page canvas.

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

Throws SetaPDF_Core_Exception

Throws SetaPDF_Core_Font_Exception

Throws SetaPDF_Core_Type_Exception

Throws SetaPDF_Core_Type_IndirectReference_Exception

Throws SetaPDF_Exception_NotImplemented

_stampByCache()

protected SetaPDF_Stamper_Stamp_RichText::_stampByCache (
SetaPDF_Core_Document $document, SetaPDF_Core_Document_Page $page, array $stampData
): bool|string|true
Parameters
$document : SetaPDF_Core_Document
 
$page : SetaPDF_Core_Document_Page
 
$stampData : array
 
Exceptions

Throws SetaPDF_Core_Exception

Throws SetaPDF_Stamper_Exception

getAction()

Get the current attached action.

getAlign()

getDimensions()

public SetaPDF_Stamper_Stamp::getDimensions (
void
): array

Get the stamp dimension.

getHeight()

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

Get the height of this stamp.

Proxy method to SetaPDF_Core_Text_RichTextBlock::getHeight() of the rich-text block instance.

Exceptions

Throws SetaPDF_Core_Exception

See

getOpacity()

public SetaPDF_Stamper_Stamp::getOpacity (
void
): float

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

Exceptions

Throws SetaPDF_Core_Type_Exception

getOriginY()

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

Exceptions

Throws SetaPDF_Core_Type_Exception

getPaddingBottom()

getPaddingLeft()

getPaddingRight()

getPaddingTop()

getRichTextBlock()

Access the rich-text block instance.

IF YOU MAKE CHANGES OUTSIDE THE STAMP CLASS, MAKE SURE THAT YOU CALL {updateCacheCounter()} AFTERWARDS.

getText()

public SetaPDF_Stamper_Stamp_RichText::getText (
void
): string

getTextWidth()

public SetaPDF_Stamper_Stamp_RichText::getTextWidth (
void
): int|float

Returns the width of the rich-text stamp without padding.

Exceptions

Throws SetaPDF_Core_Exception

See

getVisibility()

public SetaPDF_Stamper_Stamp::getVisibility (
void
): null|string

Get the visibility of the stamp object.

getWidth()

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

Get the width of this stamp.

Proxy method to SetaPDF_Core_Text_RichTextBlock::getWidth() of the rich-text block instance.

Exceptions

Throws SetaPDF_Core_Exception

See

setAction()

Add an action object to the stamp object.

Parameters
$action : SetaPDF_Core_Document_Action

The action object

setAlign()

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

Set the text alignment.

Parameters
$align : string
 
See

setBorderWidth()

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

Set the border width.

Parameters
$borderWidth : int|float
 
See

setDefaultFontFamily()

public SetaPDF_Stamper_Stamp_RichText::setDefaultFontFamily (
string $fontFamily
): void
Parameters
$fontFamily : string
 
See

setDefaultFontSize()

public SetaPDF_Stamper_Stamp_RichText::setDefaultFontSize (
int|float $fontSize
): void
Parameters
$fontSize : int|float
 
See

setDefaultLineHeight()

public SetaPDF_Stamper_Stamp_RichText::setDefaultLineHeight (
int|float $lineHeight
): void
Parameters
$lineHeight : int|float

Only unitless line-heights are supported here like 1 or 1.4

setLink()

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

Set a link onto the stamp.

Parameters
$uri : string

The link

Exceptions

Throws SetaPDF_Core_Type_Exception

See

setOpacity()

public SetaPDF_Stamper_Stamp::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()

public SetaPDF_Stamper_Stamp::setOptionalContentGroup (
[ SetaPDF_Core_Document_OptionalContent_Group|null $optionalContentGroup = null ]
): void

Set the optional content group for this stamp.

Parameters
$optionalContentGroup : SetaPDF_Core_Document_OptionalContent_Group|null
 

setPadding()

public SetaPDF_Stamper_Stamp_RichText::setPadding (
int|float $padding
): void

Set the padding.

Parameters
$padding : int|float
 
See

setPaddingBottom()

public SetaPDF_Stamper_Stamp_RichText::setPaddingBottom (
int|float $paddingBottom
): void

Set the bottom padding.

Parameters
$paddingBottom : int|float
 
See

setPaddingLeft()

public SetaPDF_Stamper_Stamp_RichText::setPaddingLeft (
int|float $paddingLeft
): void

Set the left padding.

Parameters
$paddingLeft : int|float
 
See

setPaddingRight()

public SetaPDF_Stamper_Stamp_RichText::setPaddingRight (
int|float $paddingRight
): void

Set the right padding.

Parameters
$paddingRight : int|float
 
See

setPaddingTop()

public SetaPDF_Stamper_Stamp_RichText::setPaddingTop (
int|float $paddingTop
): void

Set the top padding.

Parameters
$paddingTop : int|float
 
See

setText()

public SetaPDF_Stamper_Stamp_RichText::setText (
string $text [, string $locale = 'en_US' ]
): void
Parameters
$text : string

A UTF-8 string with a subset of HTML tags and CSS properties in style-parameter.

$locale : string

INTL locale used for the break behaviour

See

setTextWidth()

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

Set the width of the text in the rich-text stamp. Padding is not included in this width.

Parameters
$width : int|float
 
See

setVisibility()

public SetaPDF_Stamper_Stamp::setVisibility (
null|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 : null|string

Use the constants VISIBILITY_XXX or null(equal to VISIBILITY_ALL)

Exceptions

Throws InvalidArgumentException

stamp()

public SetaPDF_Stamper_Stamp::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 SetaPDF_Core_SecHandler_Exception

Throws SetaPDF_Core_Type_Exception

Throws SetaPDF_Stamper_Exception

updateCacheCounter()

Updates the cache counter.