phpdftk API Documentation

AppearanceGenerator
in package

FinalYes

Generates appearance streams for interactive form fields.

Produces FormXObject instances that render field UI (borders, text, check marks, etc.) so fields are visible without relying on /NeedAppearances=true.

Each generate*() method returns a FormXObject that should be registered with the writer and referenced from the field's widget annotation's /AP/N entry.

Table of Contents

Methods

buildAppearanceDict()  : AppearanceDict
Build an AppearanceDict with a single normal appearance.
buildStateAppearanceDict()  : AppearanceDict
Build an AppearanceDict for checkbox/radio with on/off states.
checkbox()  : FormXObject}
Generate appearance streams for a checkbox field.
choiceField()  : FormXObject
Generate a normal appearance for a choice field (combo/list box).
combTextField()  : FormXObject
Generate a comb text field appearance (equally-spaced character cells).
passwordField()  : FormXObject
Generate a password field appearance (renders dots instead of text).
pushButton()  : FormXObject
Generate a push button appearance.
radioButton()  : FormXObject}
Generate appearance streams for a radio button.
signatureField()  : FormXObject
Generate a signature field appearance.
textField()  : FormXObject
Generate a normal appearance for a text field.
textFieldMultiLine()  : FormXObject
Generate a multi-line text field appearance.

Methods

checkbox()

Generate appearance streams for a checkbox field.

public static checkbox(PdfArray $rect[, float $borderWidth = 1.0 ]) : FormXObject}

Returns two FormXObjects: one for the "on" state (check mark) and one for the "off" state (empty box).

Parameters
$rect : PdfArray
$borderWidth : float = 1.0
Return values
FormXObject}

choiceField()

Generate a normal appearance for a choice field (combo/list box).

public static choiceField(PdfArray $rect, string $fontName, float $fontSize[, string $selectedValue = '' ][, float $borderWidth = 1.0 ][, FontContext|null $fontContext = null ]) : FormXObject

Renders the currently selected value text in a bordered box.

Parameters
$rect : PdfArray
$fontName : string
$fontSize : float
$selectedValue : string = ''
$borderWidth : float = 1.0
$fontContext : FontContext|null = null

Custom font context for composite font rendering

Return values
FormXObject

combTextField()

Generate a comb text field appearance (equally-spaced character cells).

public static combTextField(PdfArray $rect, string $fontName, float $fontSize[, string $value = '' ][, int $maxLen = 10 ][, float $borderWidth = 1.0 ][, FontContext|null $fontContext = null ]) : FormXObject

Each character is centered in its own cell, with vertical dividers.

Parameters
$rect : PdfArray
$fontName : string
$fontSize : float
$value : string = ''
$maxLen : int = 10

Maximum number of characters (/MaxLen)

$borderWidth : float = 1.0
$fontContext : FontContext|null = null

Custom font context for composite font rendering

Return values
FormXObject

passwordField()

Generate a password field appearance (renders dots instead of text).

public static passwordField(PdfArray $rect, string $fontName, float $fontSize[, int $characterCount = 0 ][, float $borderWidth = 1.0 ]) : FormXObject
Parameters
$rect : PdfArray
$fontName : string
$fontSize : float
$characterCount : int = 0
$borderWidth : float = 1.0
Return values
FormXObject

pushButton()

Generate a push button appearance.

public static pushButton(PdfArray $rect, string $fontName, float $fontSize[, string $label = '' ][, float $borderWidth = 1.5 ][, FontContext|null $fontContext = null ]) : FormXObject
Parameters
$rect : PdfArray
$fontName : string
$fontSize : float
$label : string = ''
$borderWidth : float = 1.5
$fontContext : FontContext|null = null

Custom font context for composite font rendering

Return values
FormXObject

radioButton()

Generate appearance streams for a radio button.

public static radioButton(PdfArray $rect[, float $borderWidth = 1.0 ]) : FormXObject}
Parameters
$rect : PdfArray
$borderWidth : float = 1.0
Return values
FormXObject}

signatureField()

Generate a signature field appearance.

public static signatureField(PdfArray $rect, string $fontName, float $fontSize[, string $signer = '' ][, string $reason = '' ][, string $date = '' ][, float $borderWidth = 1.0 ][, FontContext|null $fontContext = null ]) : FormXObject

Renders a bordered box with signature information text.

Parameters
$rect : PdfArray
$fontName : string
$fontSize : float
$signer : string = ''
$reason : string = ''
$date : string = ''
$borderWidth : float = 1.0
$fontContext : FontContext|null = null

Custom font context for composite font rendering

Return values
FormXObject

textField()

Generate a normal appearance for a text field.

public static textField(PdfArray $rect, string $fontName, float $fontSize[, string $value = '' ][, int $justification = 0 ][, float $borderWidth = 1.0 ][, FontContext|null $fontContext = null ]) : FormXObject

Draws a border rectangle and renders the field value using the specified font resource name and size.

Parameters
$rect : PdfArray

Widget rectangle [x1, y1, x2, y2]

$fontName : string

Font resource name (e.g., "F1")

$fontSize : float

Font size in points

$value : string = ''

Current field value text

$justification : int = 0

0=left, 1=center, 2=right

$borderWidth : float = 1.0

Border line width

$fontContext : FontContext|null = null

Custom font context for composite font rendering

Return values
FormXObject

textFieldMultiLine()

Generate a multi-line text field appearance.

public static textFieldMultiLine(PdfArray $rect, string $fontName, float $fontSize[, string $value = '' ][, float $leading = 0 ][, float $borderWidth = 1.0 ][, float $charWidth = 0.5 ][, FontContext|null $fontContext = null ]) : FormXObject

Word-wraps text to fit the field width, rendering multiple lines with the given leading (line height).

Parameters
$rect : PdfArray

Widget rectangle [x1, y1, x2, y2]

$fontName : string

Font resource name (e.g., "F1")

$fontSize : float

Font size in points

$value : string = ''

Multi-line field value text

$leading : float = 0

Line height in points (default: fontSize × 1.2)

$borderWidth : float = 1.0

Border line width

$charWidth : float = 0.5

Approximate average character width as fraction of fontSize (default 0.5)

$fontContext : FontContext|null = null

Custom font context for composite font rendering

Return values
FormXObject

        
On this page

Search results