JavaScript

JavaScript PDF class

Namespace: Com\Tecnick\Pdf

abstract class JavaScript extends CSS

Extends: CSS

Source: src/JavaScript.php:53

JavaScript PDF class

Types

TRadioButtonItem

array{
    'n': int,
    'def': string,
}

TRadioButton

array{
    'n': int,
    '#readonly#': bool,
    'kids': array<TRadioButtonItem>,
}

Methods

addContentAsEmbeddedFile()

Add string content as an embedded file.

If a file with the same name already exists, it will be ignored.

public addContentAsEmbeddedFile(
    string $file,
    string $content,
    string $mime = 'application/octet-stream',
    string|AFRelationship $afrel = 'Source',
    string $desc = ''
): void

Parameters:

  • $file (string): File name to be used a key for the embedded file.
  • $content (string): Content of the embedded file.
  • $mime (string): MIME type of the file (e.g., ‘application/xml’).
  • $afrel (string|AFRelationship): AFRelationship value (Source, Data, Alternative, Supplement, Unspecified) or enum.
  • $desc (string): Optional description of the file.

Throws:

Source: src/JavaScript.php:772

addEmbeddedFile()

Add an embedded file.

If a file with the same name already exists, it will be ignored.

public addEmbeddedFile(
    string $file,
    string $mime = 'application/octet-stream',
    string|AFRelationship $afrel = 'Source',
    string $desc = ''
): void

Parameters:

  • $file (string): File name (absolute or relative path).
  • $mime (string): MIME type of the file (e.g., ‘application/xml’).
  • $afrel (string|AFRelationship): AFRelationship value (Source, Data, Alternative, Supplement, Unspecified) or enum.
  • $desc (string): Optional description of the file.

Throws:

Source: src/JavaScript.php:721

addFFButton()

Adds an annotation button form field.

public addFFButton(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    string $caption,
    string|array<string,mixed> $action,
    TAnnotOpts $opt = ['subtype' => 'Widget'],
    array<string,mixed> $jsp = []
): int

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $caption (string): caption.
  • $action (string|array<string,mixed>): action triggered by pressing the button. Use a string to specify a javascript action. Use an array to specify a form action options as in section 12.7.5 of PDF32000_2008.
  • $opt (TAnnotOpts): Array of options (Annotation Types) - all lowercase.
  • $jsp (array<string,mixed>): javascript field properties (see: Javascript for Acrobat API reference).

Returns: int: PDF Object ID.

Throws:

Source: src/JavaScript.php:1503

addFFCheckBox()

Adds an annotation checkbox form field.

public addFFCheckBox(
    string $name,
    float $posx,
    float $posy,
    float $width,
    string $onvalue = 'Yes',
    bool $checked = false,
    TAnnotOpts $opt = ['subtype' => 'Widget'],
    array<string,mixed> $jsp = []
): int

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $onvalue (string): Value to be returned if selected.
  • $checked (bool): Define the initial state.
  • $opt (TAnnotOpts): Array of options (Annotation Types) - all lowercase.
  • $jsp (array<string,mixed>): javascript field properties (see: Javascript for Acrobat API reference).

Returns: int: PDF Object ID.

Throws:

Source: src/JavaScript.php:1664

addFFComboBox()

Adds an annotation combobox (select) form field.

public addFFComboBox(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    array{string, string}[]|string[] $values,
    TAnnotOpts $opt = ['subtype' => 'Widget'],
    array<string,mixed> $jsp = []
): int

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $values (array{string, string}[]|string[]): List of selection values.
  • $opt (TAnnotOpts): Array of options (Annotation Types) - all lowercase.
  • $jsp (array<string,mixed>): javascript field properties (see: Javascript for Acrobat API reference).

Returns: int: PDF Object ID.

Throws:

Source: src/JavaScript.php:1741

addFFListBox()

Adds an annotation listbox (select) form field.

public addFFListBox(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    array{string, string}[]|string[] $values,
    TAnnotOpts $opt = ['subtype' => 'Widget'],
    array<string,mixed> $jsp = []
): int

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $values (array{string, string}[]|string[]): List of selection values.
  • $opt (TAnnotOpts): Array of options (Annotation Types) - all lowercase.
  • $jsp (array<string,mixed>): javascript field properties (see: Javascript for Acrobat API reference).

Returns: int: PDF Object ID.

Throws:

Source: src/JavaScript.php:1814

addFFRadioButton()

Adds an annotation radiobutton form field.

public addFFRadioButton(
    string $name,
    float $posx,
    float $posy,
    float $width,
    string $onvalue = 'On',
    bool $checked = false,
    TAnnotOpts $opt = ['subtype' => 'Widget'],
    array<string,mixed> $jsp = []
): int

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $onvalue (string): Value to be returned if selected.
  • $checked (bool): Define the initial state.
  • $opt (TAnnotOpts): Array of options (Annotation Types) - all lowercase.
  • $jsp (array<string,mixed>): javascript field properties (see: Javascript for Acrobat API reference).

Returns: int: PDF Object ID.

Throws:

Source: src/JavaScript.php:1884

addFFText()

Adds an annotation text form field.

public addFFText(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    TAnnotOpts $opt = ['subtype' => 'text'],
    array<string,mixed> $jsp = []
): int

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $opt (TAnnotOpts): Array of options (Annotation Types) - all lowercase.
  • $jsp (array<string,mixed>): javascript field properties (see: Javascript for Acrobat API reference).

Returns: int: PDF Object ID.

Throws:

Source: src/JavaScript.php:1984

Defines the page and vertical position an internal link points to.

public addInternalLink(int $page = -1, float $posy = 0): string

Parameters:

  • $page (int): Page number.
  • $posy (float): Vertical position.

Returns: string: Internal link identifier to be used with setLink().

Source: src/JavaScript.php:983

addJSButton()

Adds a JavaScript button form field.

public addJSButton(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    string $caption,
    string $action,
    array<string,string> $jsp = []
): void

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $caption (string): caption.
  • $action (string): action triggered by pressing the button. A string specifying the JavaScript action to run.
  • $jsp (array<string,string>): javascript field properties (see: Javascript for Acrobat API reference).

Throws:

Source: src/JavaScript.php:2068

addJSCheckBox()

Adds a JavaScript checkbox form field.

public addJSCheckBox(
    string $name,
    float $posx,
    float $posy,
    float $width,
    array<string,string> $jsp = []
): void

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $jsp (array<string,string>): javascript field properties (see: Javascript for Acrobat API reference).

Throws:

Source: src/JavaScript.php:2097

addJSComboBox()

Adds a JavaScript combobox (select) form field.

public addJSComboBox(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    array{string, string}[]|string[] $values,
    array<string,string> $jsp = []
): void

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $values (array{string, string}[]|string[]): List of selection values.
  • $jsp (array<string,string>): javascript field properties (see: Javascript for Acrobat API reference).

Throws:

Source: src/JavaScript.php:2116

addJSListBox()

Adds a JavaScript listbox (select) form field.

public addJSListBox(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    array{string, string}[]|string[] $values,
    array<string,string> $jsp = []
): void

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $values (array{string, string}[]|string[]): List of selection values.
  • $jsp (array<string,string>): javascript field properties (see: Javascript for Acrobat API reference).

Throws:

Source: src/JavaScript.php:2151

addJSRadioButton()

Adds a JavaScript radiobutton form field.

public addJSRadioButton(
    string $name,
    float $posx,
    float $posy,
    float $width,
    array<string,string> $jsp = []
): void

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $jsp (array<string,string>): javascript field properties (see: Javascript for Acrobat API reference).

Throws:

Source: src/JavaScript.php:2184

addJSText()

Adds a JavaScript text form field.

public addJSText(
    string $name,
    float $posx,
    float $posy,
    float $width,
    float $height,
    array<string,string> $jsp = []
): void

Parameters:

  • $name (string): field name.
  • $posx (float): horizontal position in user units (LTR).
  • $posy (float): vertical position in user units (LTR).
  • $width (float): width in user units.
  • $height (float): height in user units.
  • $jsp (array<string,string>): javascript field properties (see: Javascript for Acrobat API reference).

Throws:

Source: src/JavaScript.php:2202

addRawJavaScriptObj()

Add a raw javascript string as new object.

public addRawJavaScriptObj(string $script, bool $onload = false): int

Parameters:

  • $script (string): Raw Javascript string.
  • $onload (bool): Set to true to execute the script when opening the document.

Returns: int: PDF object ID or -1 in case of error.

Source: src/JavaScript.php:236

addXObjectContent()

Add the specified raw PDF content to the XObject template.

public addXObjectContent(string $tid, string $data): void

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $data (string): The raw PDF content data to add.

Source: src/JavaScript.php:1311

addXObjectExtGStateID()

Add the specified ExtGState ID to the XObject template.

public addXObjectExtGStateID(string $tid, int $key): void

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $key (int): The ExtGState key to add.

Source: src/JavaScript.php:1391

addXObjectFontID()

Add the specified Font ID to the XObject template.

public addXObjectFontID(string $tid, string $key): void

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $key (string): The Font key to add.

Source: src/JavaScript.php:1359

addXObjectGradientID()

Add the specified Gradient ID to the XObject template.

public addXObjectGradientID(string $tid, int $key): void

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $key (int): The Gradient key to add.

Source: src/JavaScript.php:1375

addXObjectImageID()

Add the specified Image ID to the XObject template.

public addXObjectImageID(string $tid, int $key): void

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $key (int): The Image key to add.

Source: src/JavaScript.php:1343

addXObjectSpotColorID()

Add the specified SpotColor ID to the XObject template.

public addXObjectSpotColorID(string $tid, string $key): void

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $key (string): The SpotColor key to add.

Source: src/JavaScript.php:1407

addXObjectXObjectID()

Add the specified XObject ID to the XObject template.

public addXObjectXObjectID(string $tid, string $key): void

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $key (string): The XObject key to add.

Source: src/JavaScript.php:1327

appendRawJavaScript()

Append raw javascript string to the global one.

public appendRawJavaScript(string $script): void

Parameters:

  • $script (string): Raw Javascript string.

Source: src/JavaScript.php:219

exitXObjectTemplate()

Exit from the XObject template mode.

See: newXObjectTemplate.

public exitXObjectTemplate(): void

Throws:

Source: src/JavaScript.php:1150

getDefJSAnnotProp()

Returns the default Javascript Annotation properties.

Possible values are described on official Javascript for Acrobat API reference.

public getDefJSAnnotProp(): array<string,mixed>

Returns: array<string,mixed>

Source: src/JavaScript.php:327

getXObjectTemplate()

Returns the PDF code to render the specified XObject template.

See: newXObjectTemplate.

public getXObjectTemplate(
    string $tid,
    float $posx = 0,
    float $posy = 0,
    float $width = 0,
    float $height = 0,
    string $valign = 'T',
    string $halign = 'L'
): string

Parameters:

  • $tid (string): The XObject Template object as returned by the newXObjectTemplate method.
  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $width (float): Width.
  • $height (float): Height.
  • $valign (string): Vertical alignment inside the specified box: T=top; C=center; B=bottom.
  • $halign (string): Horizontal alignment inside the specified box: L=left; C=center; R=right.

Returns: string: The PDF code to render the specified XObject template.

Throws:

Source: src/JavaScript.php:1183

newXObjectTemplate()

Create a new XObject template and return the object id.

An XObject Template is a PDF block that is a self-contained description of any sequence of graphics objects (including path objects, text objects, and sampled images). An XObject Template may be painted multiple times, either on several pages or at several locations on the same page and produces the same results each time, subject only to the graphics state at the time it is invoked.

public newXObjectTemplate(
    float $width = 0,
    float $height = 0,
    ?TGTransparency $transpgroup = null
): string

Parameters:

  • $width (float): Width of the XObject.
  • $height (float): Height of the XObject.
  • $transpgroup (?TGTransparency): Optional group attributes.

Returns: string: XObject template object ID.

Throws:

Source: src/JavaScript.php:1100

setAnnotation()

Add an annotation and returns the object id.

public setAnnotation(
    float $posx,
    float $posy,
    float $width,
    float $height,
    string $txt,
    TAnnotOpts $opt = ['subtype' => 'text']
): int

Parameters:

  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $width (float): Width.
  • $height (float): Height.
  • $txt (string): Annotation text or alternate content.
  • $opt (TAnnotOpts): Array of options (Annotation Types). The option keys are lowercase; the ‘subtype’ value is case insensitive and is normalized to the ISO 32000-1 annotation type name.

Returns: int: Object ID.

Throws:

Source: src/JavaScript.php:885

setBookmark()

Add a bookmark entry.

public setBookmark(
    string $name,
    string $link = '',
    int $level = 0,
    int $page = -1,
    float $posx = 0,
    float $posy = 0,
    string $fstyle = '',
    string $color = ''
): void

Parameters:

  • $name (string): Bookmark description that will be printed in the TOC.
  • $link (string): (Optional) URL to open when the link is clicked or an identifier returned by addInternalLink(). A single character prefix may be used to specify the link action:
    • ‘#’ = internal destination
    • ‘%’ = embedded PDF file
    • ‘*’ = embedded generic file
  • $level (int): Bookmark level (minimum 0).
  • $page (int): Page number.
  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $fstyle (string): Font style. Possible values are (case insensitive):
    • regular (default)
    • B: bold
    • I: italic
    • U: underline
    • D: strikeout (linethrough)
    • O: overline
  • $color (string): Color name.

Source: src/JavaScript.php:1039

setDefJSAnnotProp()

Set the default Javascript Annotation properties.

Possible values are described on official Javascript for Acrobat API reference. Annotation options can be directly specified using the ‘aopt’ entry.

public setDefJSAnnotProp(array<string,mixed> $data): void

Parameters:

  • $data (array<string,mixed>)

Source: src/JavaScript.php:316

Creates a link in the specified area.

A link annotation represents either a hypertext link to a destination elsewhere in the document.

public setLink(float $posx, float $posy, float $width, float $height, string $link): int

Parameters:

  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $width (float): Width.
  • $height (float): Height.
  • $link (string): URL to open when the link is clicked or an identifier returned by addInternalLink(). A single character prefix may be used to specify the link action:
    • ‘#’ = internal destination
    • ‘%’ = embedded PDF file
    • ‘*’ = embedded generic file

Returns: int: Object ID (Add to a page via: $pdf->page->addAnnotRef($aoid);).

Throws:

Source: src/JavaScript.php:969

setNamedDestination()

Add a named destination.

public setNamedDestination(string $name, int $page = -1, float $posx = 0, float $posy = 0): string

Parameters:

  • $name (string): Named destination (must be unique).
  • $page (int): Page number.
  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.

Returns: string: Destination name.

Source: src/JavaScript.php:1003

Inherited members

From Base

From Cell

From CSS

From SVG

  • addSVG(): Add a new SVG image and return its object ID.
  • getSetSVG(): Get the PDF output string to print the specified SVG object.
  • setLink(): Create a link annotation in the specified rectangular area.

From Text