HTML

HTML PDF class

Namespace: Com\Tecnick\Pdf

abstract class HTML extends JavaScript

Extends: JavaScript

Source: src/HTML.php:282

HTML PDF class

Types

THTMLTableCell

array{
    cellx: float,
    cellw: float,
    colindex: int,
    colspan: int,
    contenth: float,
    valign: string,
    bstyles: array<int|string, BorderStyle>,
    fillstyle: ?BorderStyle,
    buffer: string
}

THTMLTableRowspanCell

array{
    cellx: float,
    cellw: float,
    colindex: int,
    colspan: int,
    rowtop: float,
    rowsremaining: int,
    usedheight: float,
    contenth: float,
    valign: string,
    bstyles: array<int|string, BorderStyle>,
    fillstyle: ?BorderStyle,
    buffer: string
}

THTMLTableState

array{
    originx: float,
    originy: float,
    captiontopy: float,
    width: float,
    dir: string,
    cols: int,
    colwidth: float,
    colwidths: array<int, float>,
    cellspacingh: float,
    cellspacingv: float,
    cellpadding: float,
    collapse: bool,
    hascellborders: bool,
    prevrowbottom: array<int, BorderStyle>,
    rowtop: float,
    rowheight: float,
    minheight: float,
    domkey: int,
    colindex: int,
    cells: array<int, THTMLTableCell>,
    occupied: array<int, int>,
    rowspans: array<int, THTMLTableRowspanCell>,
    regionoffset: float
}

THTMLTableCellContext

array{
    originx: float,
    originy: float,
    maxwidth: float,
    maxheight: float,
    lineadvance: float,
    linebottom: float,
    lineascent: float,
    linewordspacing: float,
    linewrapped: bool,
    rowtop: float,
    cellx: float,
    cellw: float,
    colindex: int,
    colspan: int,
    padding: array{'T': float, 'R': float, 'B': float, 'L': float},
    margin: array{'T': float, 'R': float, 'B': float, 'L': float},
    bstyles: array<int|string, BorderStyle>,
    fillstyle: ?BorderStyle,
    rowspan: int,
    valign: string,
    buffer: string
}

THTMLAttrib

array{
    'align': bool|float|string,
    'attribute': array<string, string|array<string, mixed>>,
    'caption-top-html'?: string,
    'caption-bottom-html'?: string,
    'caption-side': string,
    'bgcolor': bool|float|string,
    'block': bool,
    'border-collapse': string,
    'border-spacing'?: TCSSBorderSpacing,
    'border': array<string, BorderStyle>,
    'clip': bool,
    'cols': int,
    'content': string,
    'cssdata': array<string, TCSSData>,
    'csssel': array<string>,
    'clear': string,
    'dir': string,
    'display': string,
    'empty-cells': string,
    'elkey': int,
    'fgcolor': string,
    'fill': bool,
    'font-size-adjust': float|string,
    'font-stretch': float,
    'font-variant': string,
    'fontname': string,
    'fontsize': float,
    'fontstyle': string,
    'height': float,
    'hide': bool,
    'letter-spacing': float,
    'line-height': float,
    'line-height-absolute'?: float,
    'line-height-font-size-basis'?: bool,
    'list-style-position': string,
    'listtype': string,
    'listtypeset': bool,
    'float': string,
    'margin': array<string, float>,
    'opening': bool,
    'orphans': int,
    'overflow-wrap'?: string,
    'page': string,
    'padding': array<string, float>,
    'parent': int,
    'pendingcellpadding'?: float,
    'pendingcellspacingh'?: float,
    'pendingcellspacingv'?: float,
    'pendingcolwidths'?: array<int, float>,
    'position': string,
    'quotes': string,
    'rows': int,
    'self': bool,
    'stroke': float,
    'strokecolor': string,
    'childblockbottom'?: float,
    'ctxoriginx'?: float,
    'ctxmaxwidth'?: float,
    'ctxregionoffset'?: float,
    'inlineblocknextx'?: float,
    'inlineblockrowy'?: float,
    'inlineblockpageid'?: int,
    'table-layout': string,
    'style': array<string, string>,
    'list-style-image'?: string,
    'tag': bool,
    'text-indent': float,
    'text-transform': string,
    'thead': string,
    'trids': array<int>,
    'valign': string,
    'value': string,
    'white-space': string,
    'widows': int,
    'word-break'?: string,
    'word-spacing': float,
    'width': float,
    'x': float,
    'y': float,
}

THTMLBlockBuf

array{
    openkey: int,
    bx: float,
    by: float,
    bw: float,
    buffer: string,
    celldepth: int,
    decorate: bool
}

THTMLRenderContext

array{
    'cellctx': array{
        originx: float,
        originy: float,
        lineoriginx: float,
        maxwidth: float,
        maxheight: float,
        floatrowleftw: float,
        floatrowrightw: float,
        floatrowtop: float,
        floatrowbottom: float,
        lineadvance: float,
        linebottom: float,
        lineascent: float,
        lineascentnolookahead: bool,
        linewordspacing: float,
        linewrapped: bool,
        textindentapplied: bool,
        firstlineinset: float,
        pendingblockmarginb: float,
        activepage?: string,
        regionoffset?: float,
        basefont: string
    },
    'currentkey'?: int,
    'fontcache': array<string, array<string, mixed>>,
    'liststack': array<int, array{
        type: string,
        count: int,
        indent: float
    }>,
    'tablestack': array<int, THTMLTableState>,
    'bcellctx': array<int, THTMLTableCellContext>,
    'blockbuf': array<int, THTMLBlockBuf>,
    'linkstack': array<int, string>,
    'listack': array<int, array{
        originx: float,
        maxwidth: float
    }>,
    'prelevel': int,
    'quotelevel': int,
    'dom': array<int, THTMLAttrib>,
}

THTMLRtlPiece

array{
    key: int,
    text: string,
    image: bool,
    src: string,
    width: float,
    height: float,
    valign: string
}

THTMLRtlSegment

array{
    key: int,
    text: string,
    width: float,
    ascent: float,
    image: bool,
    height: float,
    valign: string,
    src: string
}

Methods

addHTMLCell()

Adds an HTML block inside a rectangular cell.

Accounts for automatic page and region breaks while appending page-specific content directly to each affected page stream.

public addHTMLCell(
    string $html,
    float $posx = 0,
    float $posy = 0,
    float $width = 0,
    float $height = 0,
    ?TCellDef $cell = null,
    array<int|string,BorderStyle> $styles = []
): void

Parameters:

  • $html (string): HTML code to be processed.
  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $width (float): Width.
  • $height (float): Height.
  • $cell (?TCellDef): Optional to overwrite cell parameters for padding, margin etc. The margin and padding values are in points.
  • $styles (array<int|string,BorderStyle>): Cell border styles (see: getCurrentStyleArray).

Throws:

Source: src/HTML.php:15916

getHTMLCell()

Returns the PDF code to render an HTML block inside a rectangular cell.

public getHTMLCell(
    string $html,
    float $posx = 0,
    float $posy = 0,
    float $width = 0,
    float $height = 0,
    ?TCellDef $cell = null,
    array<int|string,BorderStyle> $styles = []
): string

Parameters:

  • $html (string): HTML code to be processed.
  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $width (float): Width.
  • $height (float): Height.
  • $cell (?TCellDef): Optional to overwrite cell parameters for padding, margin etc. The margin and padding values are in points.
  • $styles (array<int|string,BorderStyle>): Cell border styles (see: getCurrentStyleArray).

Returns: string

Throws:

Source: src/HTML.php:15821

getHTMLDOMCSSData()

Returns the styles array that apply for the selected HTML tag.

public getHTMLDOMCSSData(
    array<int,THTMLAttrib> &$dom,
    array<string,string> $css,
    int $key
): void

Parameters:

  • $dom (array<int,THTMLAttrib>)
  • $css (array<string,string>)
  • $key (int): Key of the current HTML tag.

Source: src/HTML.php:1863

isValidCSSSelectorForTag()

Returns true if the CSS selector is valid for the selected HTML tag.

public isValidCSSSelectorForTag(array<int,THTMLAttrib> &$dom, int $key, string $selector): bool

Parameters:

  • $dom (array<int,THTMLAttrib>)
  • $key (int): key of the current HTML tag
  • $selector (string): CSS selector string

Returns: bool: True if the selector is valid, false otherwise

Source: src/HTML.php:2047

parseHTMLAttributes()

Parst HTML DOM attributes.

public parseHTMLAttributes(array<int,THTMLAttrib> &$dom, int $key, bool $thead): void

Parameters:

  • $dom (array<int,THTMLAttrib>)
  • $key (int): key of the current HTML tag.
  • $thead (bool)

Throws:

Source: src/HTML.php:6069

parseHTMLStyleAttributes()

Parse HTML DOM Style attributes.

public parseHTMLStyleAttributes(array<int,THTMLAttrib> &$dom, int $key, int $parentkey): void

Parameters:

  • $dom (array<int,THTMLAttrib>)
  • $key (int): key of the current HTML tag.
  • $parentkey (int): Key of the parent element.

Throws:

Source: src/HTML.php:2772

setHtmlImageImportResize()

Enable or disable HTML raster image downscaling on import.

When enabled, raster images rendered smaller than their intrinsic size are imported at a reduced pixel size before placement.

public setHtmlImageImportResize(bool $enabled): void

Parameters:

  • $enabled (bool)

Source: src/HTML.php:12756

setHTMLMonospaceFont()

Set the monospaced font used for <pre>, <code> and <tt> elements.

PDF/UA requires every font to be embedded and the default Courier is a non-embedded standard-14 font, so an embedded monospace font must be set (after inserting it with the font stack) for tagged or accessible PDFs.

public setHTMLMonospaceFont(string $fontname): void

Parameters:

  • $fontname (string)

Source: src/HTML.php:6376

setHtmlVSpace()

Set custom vertical spacing for HTML block tags.

Each tag entry has two positions: [0] = space added before the opening tag (top margin) [1] = space added after the closing tag (bottom margin)

Each position is an array with optional keys: ‘h’ => float (fixed height in user units) ’n’ => int (number of line-heights to add)

Example: $pdf->setHtmlVSpace([‘p’ => [[‘h’ => 0, ’n’ => 1], [‘h’ => 0, ’n’ => 0]]]);

public setHtmlVSpace(array<string,array<int,array{h?: float|int, n?: int}>> $tagvs): void

Parameters:

  • $tagvs (array<string,array<int,array{h?: float|int, n?: int}>>)

Source: src/HTML.php:12745

setULLIDot()

Sets the default symbol to be used as unordered-list (UL) list-item (LI) bullet.

public setULLIDot(string $sym = '!'): void

Parameters:

  • $sym (string): This can be one of the values in self::LIST_SYMBOL or an image specified as:‘img|type|width|height|image.ext’).

Source: src/HTML.php:6886

strTrim()

Trim the input string.

public strTrim(string $str, string $replace = ''): string

Parameters:

  • $str (string): string to trim.
  • $replace (string): string that replace spaces.

Returns: string: trimmed string.

Source: src/HTML.php:836

strTrimLeft()

Left trim the input string.

public strTrimLeft(string $str, string $replace = ''): string

Parameters:

  • $str (string): string to trim.
  • $replace (string): string that replace spaces.

Returns: string: left trimmed string.

Source: src/HTML.php:810

strTrimRight()

Right trim the input string.

public strTrimRight(string $str, string $replace = ''): string

Parameters:

  • $str (string): string to trim.
  • $replace (string): string that replace spaces.

Returns: string: right trimmed string.

Source: src/HTML.php:823

tidyHTML()

Cleanup HTML code (requires HTML Tidy library).

public tidyHTML(string $html, string $defcss): string

Parameters:

  • $html (string): htmlcode to fix.
  • $defcss (string): CSS to add.

Returns: string: XHTML code cleaned up.

Throws:

  • Exception: If Tidy cannot parse the input HTML.

Source: src/HTML.php:753

Inherited members

From Base

From Cell

From CSS

From JavaScript

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.

From Text