Table of contents
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:
- Exception: in case of error.
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:
- Exception: in case of error.
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
addInternalLink()
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
setLink()
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
- BORDERPOS_DEFAULT: The default relative position of the cell origin when the border is centered on the cell edge.
- BORDERPOS_EXTERNAL: The relative position of the cell origin when the border is external to the cell edge.
- BORDERPOS_INTERNAL: The relative position of the cell origin when the border is internal to the cell edge.
- ZEROCELL: Default values for cell.
- ZEROCELLBOUND: Default values for cell boundaries.
- $barcode: Barcode object.
- $cache: Cache object.
- $color: Color object.
- $encrypt: Encrypt object.
- $file: File object.
- $font: Font object.
- $graph: Graph object.
- $image: Image Import object.
- $markupFile: File object for markup-originated resources.
- $page: Page object.
- $pon: Current PDF object number.
- $uniconv: Unicode Convert object.
- defaultFileAllowedPaths(): Returns the default array of allowed file paths.
- defaultMarkupAllowedPaths(): Returns the default array of allowed file paths for markup-originated resources.
- enableDefaultPageContent(): Enable or disable the default page content.
- getWarnings(): Return the conformance warnings raised while the document was rendered.
- initClassObjects(): Initialize dependencies class objects.
- setPDFVersion(): Set the PDF version (check PDF reference for valid values).
- setRTL(): Set the default document language direction.
- toPoints(): Convert user units to internal points unit.
- toUnit(): Convert internal points to user unit.
- toYPoints(): Convert vertical user value to internal points unit.
- toYUnit(): Convert vertical internal points value to user unit.
From Cell
- setDefaultCellBorderPos(): Sets the default cell border position.
- setDefaultCellMargin(): Set the default cell margin in user units.
- setDefaultCellPadding(): Set the default cell padding in user units.
From CSS
- addGlobalCSS(): Append CSS content to the global CSS applied as a base stylesheet to all HTML rendering calls.
- resetGlobalCSS(): Reset (clear) the global CSS so no base stylesheet is applied to HTML rendering calls.
- setDefaultCSSBorderSpacing(): Set the default CSS border spacing in user units.
- setDefaultCSSMargin(): Set the default CSS margin in user units.
- setDefaultCSSPadding(): Set the default CSS padding in user units.
- setGlobalCSS(): Set the global CSS content applied as a base stylesheet to all HTML rendering calls.
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
- addArtifactContent(): Add non-semantic content wrapped as Artifact marked-content.
- addPage(): Add a new page (wrapper function for $this->page->add()).
- addTaggedFigureContent(): Add non-text graphical content as a tagged Figure block in PDF/UA mode.
- addTextCell(): Adds a text block inside a rectangular cell using relative coordinates.
- addTextCellXY(): Adds a text block inside a rectangular cell using absolute page coordinates.
- beginArtifact(): Open an Artifact marked-content block for non-semantic page content.
- beginStructElem(): Open a PDF/UA structure element bracket.
- defaultPageContent(): Sets the page common content like Header and Footer.
- enableZeroWidthBreakPoints(): Enable or disable automatic line breaking points after some non-letter character types.
- endArtifact(): Close an Artifact marked-content block opened by beginArtifact().
- endStructElem(): Close the current PDF/UA structure element bracket.
- getLastBBox(): Returns the last text fragment bounding box as {x, y, w, h} (left, top, width, height).
- getLastCellBBox(): Returns the last Cell bounding box as {x, y, w, h} (left, top, width, height).
- getLastTextBBox(): Returns the last Text bounding box as {x, y, w, h} (left, top, width, height).
- getTextCell(): Returns the PDF code to render a text block inside a rectangular cell.
- getTextLine(): Returns the PDF code to render a single line of text.
- loadTexHyphenPatterns(): Returns an array of hyphenation patterns.
- resumePdfUaTagging(): Resume structure tagging, restoring the mode returned by suspendPdfUaTagging().
- setCurrentPage(): Set the current page number (move to the specified page).
- setTexHyphenPatterns(): Sets the hyphen patterns for text.
- suspendPdfUaTagging(): Suspend structure tagging and marked-content recording.