Text

Text PDF data

Namespace: Com\Tecnick\Pdf

abstract class Text extends Cell

Extends: Cell

Source: src/Text.php:95

Text PDF data

Types

TextCellStyles

array{
    all?: StyleDataOpt, // One style applied to all four borders.
    L?: StyleDataOpt, // Left border style.
    T?: StyleDataOpt, // Top border style.
    R?: StyleDataOpt, // Right border style.
    B?: StyleDataOpt, // Bottom border style.
}

TextCellStylesLegacy

array{
    all?: StyleDataOpt, // One style applied to all four borders.
    0?: StyleDataOpt, // Top border style (legacy numeric side index).
    1?: StyleDataOpt, // Right border style (legacy numeric side index).
    2?: StyleDataOpt, // Bottom border style (legacy numeric side index).
    3?: StyleDataOpt, // Left border style (legacy numeric side index).
}

TextCellStylesInput

TextCellStyles|TextCellStylesLegacy

TextShadow

array{
    'xoffset': float,
    'yoffset': float,
    'opacity': float,
    'mode': string,
    'color': string,
}

TextLinePos

array{
    'pos': int,
    'chars': int,
    'spaces': int,
    'septype': string,
    'totwidth': float,
    'totspacewidth': float,
    'words': int,
}

TBidiLevels

array{
    'level': array<int, int>,
    'pel': array<int, int>,
}

Methods

addArtifactContent()

Add non-semantic content wrapped as Artifact marked-content.

This is the preferred API for decorative graphics and page furniture because it writes the wrapped content directly to the selected page.

public addArtifactContent(
    string $content,
    int $pid,
    string $type = '',
    string $subtype = ''
): void

Parameters:

  • $content (string): Raw PDF operators to wrap.
  • $pid (int): Page index.
  • $type (string): Optional Artifact /Type (for example ‘Pagination’).
  • $subtype (string): Optional Artifact /Subtype (for example ‘Header’ or ‘Footer’).

Throws:

Source: src/Text.php:1100

addPage()

Add a new page (wrapper function for $this->page->add()).

public addPage(PageInputData $data = []): PageData

Parameters:

Returns: PageData: Page data with additional Page ID property ‘pid’.

Throws:

Source: src/Text.php:4004

addTaggedFigureContent()

Add non-text graphical content as a tagged Figure block in PDF/UA mode.

Pass raw drawing/image operators (for example from graph or image helpers) to associate them with a Figure structure element and optional /Alt text.

public addTaggedFigureContent(
    string $content,
    int $pid,
    string $alt = '',
    TFourFloat|array{} $bbox = []
): void

Parameters:

  • $content (string): Raw drawing/image operators to place inside the Figure.
  • $pid (int): Page identifier the content is added to.
  • $alt (string): Optional alternate text written as the Figure /Alt entry.
  • $bbox (TFourFloat|array{}): Optional bounding box of the content as [llx, lly, urx, ury] in points, measured in default user space with the origin at the bottom-left page corner. Written as the /BBox Layout attribute, which PDF/UA requires for figures contained on a single page.

Throws:

Source: src/Text.php:1027

addTextCell()

Adds a text block inside a rectangular cell using relative coordinates.

Accounts for automatic line, page and region breaks.

public addTextCell(
    string $txt,
    int $pid = -1,
    float $posx = 0,
    float $posy = 0,
    float $width = 0,
    float $height = 0,
    float $offset = 0,
    float $linespace = 0,
    string|TextVAlign $valign = 'T',
    string|TextHAlign $halign = '',
    ?TCellDef $cell = null,
    TextCellStylesInput $styles = [],
    float $strokewidth = 0,
    float $wordspacing = 0,
    float $leading = 0,
    float $rise = 0,
    bool $jlast = true,
    bool $fill = true,
    bool $stroke = false,
    bool $underline = false,
    bool $linethrough = false,
    bool $overline = false,
    bool $clip = false,
    bool $drawcell = true,
    string|TextDirection $forcedir = '',
    ?TextShadow $shadow = null,
    string|TextFitMode $fit = ''
): void

Parameters:

  • $txt (string): Text string to be processed.
  • $pid (int): Page index. Omit or set it to -1 for the current page ID.
  • $posx (float): Abscissa of upper-left corner relative to the region origin X coordinate.
  • $posy (float): Ordinate of upper-left corner relative to the region origin Y coordinate.
  • $width (float): Width.
  • $height (float): Height.
  • $offset (float): Horizontal offset to apply to the line start.
  • $linespace (float): Additional space to add between lines.
  • $valign (string|TextVAlign): Text vertical alignment inside the cell: T=top; C=center; B=bottom (or enum case).
  • $halign (string|TextHAlign): Text horizontal alignment inside the cell: L=left; C=center; R=right; J=justify (or enum).
  • $cell (?TCellDef): Optional to overwrite cell parameters for padding, margin etc. The margin and padding values are in points.
  • $styles (TextCellStylesInput): Cell border styles (see: getCurrentStyleArray).
  • $strokewidth (float): Stroke width.
  • $wordspacing (float): Word spacing (use it only when justify == false).
  • $leading (float): Leading.
  • $rise (float): Text rise.
  • $jlast (bool): If true does not justify the last line when $halign == J.
  • $fill (bool): If true fills the text.
  • $stroke (bool): If true stroke the text.
  • $underline (bool): If true underline the text.
  • $linethrough (bool): If true line through the text.
  • $overline (bool): If true overline the text.
  • $clip (bool): If true activate clipping mode.
  • $drawcell (bool): If true draw the cell border.
  • $forcedir (string|TextDirection): If ‘R’ forces RTL, if ‘L’ forces LTR.
  • $shadow (?TextShadow): Text shadow parameters.
  • $fit (string|TextFitMode): Option to fit the overflowing text in the given cell dimensions (or enum case). Supported values:
    • ‘’: disabled (default)
    • ‘T’: truncate text to fit width and height
    • ‘S’: compress horizontally to best fit width
    • ‘F’: decrease font size only when text is too large

Throws:

Source: src/Text.php:597

addTextCellXY()

Adds a text block inside a rectangular cell using absolute page coordinates.

Accounts for automatic line, page and region breaks.

public addTextCellXY(
    string $txt,
    int $pid = -1,
    float $posx = 0,
    float $posy = 0,
    float $width = 0,
    float $height = 0,
    float $offset = 0,
    float $linespace = 0,
    string|TextVAlign $valign = 'T',
    string|TextHAlign $halign = '',
    ?TCellDef $cell = null,
    TextCellStylesInput $styles = [],
    float $strokewidth = 0,
    float $wordspacing = 0,
    float $leading = 0,
    float $rise = 0,
    bool $jlast = true,
    bool $fill = true,
    bool $stroke = false,
    bool $underline = false,
    bool $linethrough = false,
    bool $overline = false,
    bool $clip = false,
    bool $drawcell = true,
    string|TextDirection $forcedir = '',
    ?TextShadow $shadow = null,
    string|TextFitMode $fit = ''
): void

Parameters:

  • $txt (string): Text string to be processed.
  • $pid (int): Page index. Omit or set it to -1 for the current page ID.
  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $width (float): Width.
  • $height (float): Height.
  • $offset (float): Horizontal offset to apply to the line start.
  • $linespace (float): Additional space to add between lines.
  • $valign (string|TextVAlign): Text vertical alignment inside the cell: T=top; C=center; B=bottom (or enum case).
  • $halign (string|TextHAlign): Text horizontal alignment inside the cell: L=left; C=center; R=right; J=justify (or enum).
  • $cell (?TCellDef): Optional to overwrite cell parameters for padding, margin etc. The margin and padding values are in points.
  • $styles (TextCellStylesInput): Cell border styles (see: getCurrentStyleArray).
  • $strokewidth (float): Stroke width.
  • $wordspacing (float): Word spacing (use it only when justify == false).
  • $leading (float): Leading.
  • $rise (float): Text rise.
  • $jlast (bool): If true does not justify the last line when $halign == J.
  • $fill (bool): If true fills the text.
  • $stroke (bool): If true stroke the text.
  • $underline (bool): If true underline the text.
  • $linethrough (bool): If true line through the text.
  • $overline (bool): If true overline the text.
  • $clip (bool): If true activate clipping mode.
  • $drawcell (bool): If true draw the cell border.
  • $forcedir (string|TextDirection): If ‘R’ forces RTL, if ‘L’ forces LTR.
  • $shadow (?TextShadow): Text shadow parameters.
  • $fit (string|TextFitMode): Option to fit the overflowing text in the given cell dimensions (or enum case). Supported values:
    • ‘’: disabled (default)
    • ‘T’: truncate text to fit width and height
    • ‘S’: compress horizontally to best fit width
    • ‘F’: decrease font size only when text is too large

Throws:

Source: src/Text.php:490

beginArtifact()

Open an Artifact marked-content block for non-semantic page content.

Typical usage is for repeated page furniture (header/footer/page numbers), decorative graphics, separators, and similar visual-only content. This method returns the opening PDF operators and does not write them to the current page automatically. To persist the artifact block, append the returned string with page->addContent(…) or use addArtifactContent().

public beginArtifact(string $type = '', string $subtype = ''): string

Parameters:

  • $type (string): Optional Artifact /Type name (for example ‘Pagination’).
  • $subtype (string): Optional Artifact /Subtype name (for example ‘Header’ or ‘Footer’).

Returns: string

Source: src/Text.php:1048

beginStructElem()

Open a PDF/UA structure element bracket.

Call this before rendering the content of a logical block (e.g. <p>, <h1>). All addTextCell calls until endStructElem() share the same structure element.

public beginStructElem(
    string $role,
    int $pid,
    string|null $alt = null,
    array<string,string> $attr = [],
    bool $required = false
): void

Parameters:

  • $role (string): PDF structure role, e.g. ‘P’, ‘H1’, ‘H2’, ‘L’, ‘LI’, ‘Figure’.
  • $pid (int): Page index (from addPage / getPageId).
  • $alt (string|null): Optional alternate description written as /Alt in the structure element dictionary, typically alt-text for Figure elements.
  • $attr (array<string,string>): Optional structure element attributes, serialized as a PDF dictionary in the /A entry.
  • $required (bool): When true, the element is kept in the structure tree even if it receives no marked content (e.g. an empty table cell).

Source: src/Text.php:935

defaultPageContent()

Sets the page common content like Header and Footer.

Override this method to add custom content to all pages.

public defaultPageContent(int $pid = -1): string

Parameters:

  • $pid (int): Page index. Omit or set it to -1 for the current page ID.

Returns: string: PDF output code.

Throws:

Source: src/Text.php:4082

enableZeroWidthBreakPoints()

Enable or disable automatic line breaking points after some non-letter character types.

public enableZeroWidthBreakPoints(bool $enabled): void

Parameters:

  • $enabled (bool)

Source: src/Text.php:3874

endArtifact()

Close an Artifact marked-content block opened by beginArtifact().

Like beginArtifact(), this returns raw PDF operators and must be appended to the page content explicitly when using the low-level API.

public endArtifact(): string

Returns: string

Source: src/Text.php:1078

endStructElem()

Close the current PDF/UA structure element bracket.

The completed element (with all its MCIDs) is appended to the struct log.

public endStructElem(): void

Source: src/Text.php:972

getLastBBox()

Returns the last text fragment bounding box as {x, y, w, h} (left, top, width, height).

public getLastBBox(): TBBox

Returns: TBBox: Array of bounding box values.

Source: src/Text.php:3260

getLastCellBBox()

Returns the last Cell bounding box as {x, y, w, h} (left, top, width, height).

public getLastCellBBox(): TBBox

Returns: TBBox: Array of bounding box values.

Source: src/Text.php:3296

getLastTextBBox()

Returns the last Text bounding box as {x, y, w, h} (left, top, width, height).

public getLastTextBBox(): TBBox

Returns: TBBox: Array of bounding box values.

Source: src/Text.php:3278

getTextCell()

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

public getTextCell(
    string $txt,
    float $posx = 0,
    float $posy = 0,
    float $width = 0,
    float $height = 0,
    float $offset = 0,
    float $linespace = 0,
    string|TextVAlign $valign = 'C',
    string|TextHAlign $halign = 'C',
    ?TCellDef $cell = null,
    TextCellStylesInput $styles = [],
    float $strokewidth = 0,
    float $wordspacing = 0,
    float $leading = 0,
    float $rise = 0,
    bool $jlast = true,
    bool $fill = true,
    bool $stroke = false,
    bool $underline = false,
    bool $linethrough = false,
    bool $overline = false,
    bool $clip = false,
    bool $drawcell = true,
    string|TextDirection $forcedir = '',
    ?TextShadow $shadow = null,
    string|TextFitMode $fit = ''
): string

Parameters:

  • $txt (string): Text string to be processed.
  • $posx (float): Abscissa of upper-left corner.
  • $posy (float): Ordinate of upper-left corner.
  • $width (float): Width.
  • $height (float): Height.
  • $offset (float): Horizontal offset to apply to the line start.
  • $linespace (float): Additional space to add between lines.
  • $valign (string|TextVAlign): Text vertical alignment inside the cell: T=top; C=center; B=bottom (or enum case).
  • $halign (string|TextHAlign): Text horizontal alignment inside the cell: L=left; C=center; R=right; J=justify (or enum).
  • $cell (?TCellDef): Optional to overwrite cell parameters for padding, margin etc. The margin and padding values are in points.
  • $styles (TextCellStylesInput): Cell border styles (see: getCurrentStyleArray).
  • $strokewidth (float): Stroke width.
  • $wordspacing (float): Word spacing (use it only when justify == false).
  • $leading (float): Leading.
  • $rise (float): Text rise.
  • $jlast (bool): If true does not justify the last line when $halign == J.
  • $fill (bool): If true fills the text.
  • $stroke (bool): If true stroke the text.
  • $underline (bool): If true underline the text.
  • $linethrough (bool): If true line through the text.
  • $overline (bool): If true overline the text.
  • $clip (bool): If true activate clipping mode.
  • $drawcell (bool): If true draw the cell border.
  • $forcedir (string|TextDirection): If ‘R’ forces RTL, if ‘L’ forces LTR.
  • $shadow (?TextShadow): Text shadow parameters.
  • $fit (string|TextFitMode): Option to fit the overflowing text in the given cell dimensions (or enum case). Supported values:
    • ‘’: disabled (default)
    • ‘T’: truncate text to fit width and height
    • ‘S’: compress horizontally to best fit width
    • ‘F’: decrease font size only when text is too large

Returns: string

Throws:

Source: src/Text.php:285

getTextLine()

Returns the PDF code to render a single line of text.

public getTextLine(
    string $txt,
    float $posx = 0,
    float $posy = 0,
    float $width = 0,
    float $strokewidth = 0,
    float $wordspacing = 0,
    float $leading = 0,
    float $rise = 0,
    bool $fill = true,
    bool $stroke = false,
    bool $underline = false,
    bool $linethrough = false,
    bool $overline = false,
    bool $clip = false,
    string|TextDirection $forcedir = '',
    string $txtanchor = '',
    ?TextShadow $shadow = null
): string

Parameters:

  • $txt (string): Text string to be processed.
  • $posx (float): X position relative to the start of the current line.
  • $posy (float): Y position relative to the start of the current line (font baseline).
  • $width (float): Desired string width to force justification via word spacing (0 = automatic).
  • $strokewidth (float): Stroke width.
  • $wordspacing (float): Word spacing (use it only when width == 0).
  • $leading (float): Leading.
  • $rise (float): Text rise.
  • $fill (bool): If true fills the text.
  • $stroke (bool): If true stroke the text.
  • $underline (bool): If true underline the text.
  • $linethrough (bool): If true line through the text.
  • $overline (bool): If true overline the text.
  • $clip (bool): If true activate clipping mode.
  • $forcedir (string|TextDirection): If ‘R’ forces RTL, if ‘L’ forces LTR.
  • $txtanchor (string): Text anchor position: ‘S’=start (default), ‘M’=middle, ‘E’=end.
  • $shadow (?TextShadow): Text shadow parameters.

Returns: string

Throws:

Source: src/Text.php:2384

loadTexHyphenPatterns()

Returns an array of hyphenation patterns.

public loadTexHyphenPatterns(string $file): array<string,string>

Parameters:

Returns: array<string,string>: Array of hyphenation patterns.

Throws:

Source: src/Text.php:3750

resumePdfUaTagging()

Resume structure tagging, restoring the mode returned by suspendPdfUaTagging().

public resumePdfUaTagging(string $previous): void

Parameters:

  • $previous (string)

Source: src/Text.php:913

setCurrentPage()

Set the current page number (move to the specified page).

public setCurrentPage(int $pid = -1): PageData

Parameters:

  • $pid (int): page index. Omit or set it to -1 for the current page ID.

Returns: PageData: Page data.

Throws:

Source: src/Text.php:4024

setTexHyphenPatterns()

Sets the hyphen patterns for text.

public setTexHyphenPatterns(array<string,string> $patterns): void

Parameters:

  • $patterns (array<string,string>): Array of hyphenation patterns.

See: Com\Tecnick\Pdf\loadTexHyphenPatterns()

Source: src/Text.php:3803

suspendPdfUaTagging()

Suspend structure tagging and marked-content recording.

While suspended, beginStructElem()/endStructElem() and the marked-content helpers are no-ops, so no structure elements are appended and the per-page MCID counter does not advance.

Returns the previous mode, to be passed back to resumePdfUaTagging(). Suspensions nest.

public suspendPdfUaTagging(): string

Returns: string

Source: src/Text.php:902

Inherited members

From Base

From Cell