PdfString

Encodes a text value as a PDF string token, either through a host-supplied encoder (which may apply UTF-16, escaping, and encryption) or, when none is given, a built-in fallback.

Table of contents

Namespace: Com\Tecnick\Pdf\Sign\Output

final class PdfString

Source: src/Output/PdfString.php:44

Encodes a text value as a PDF string token, either through a host-supplied encoder (which may apply UTF-16, escaping, and encryption) or, when none is given, a built-in fallback.

The fallback emits a literal string for printable ASCII, escaping the three delimiters. Everything else is emitted as a UTF-16BE hex string with a byte order mark: raw bytes above 0x7E in a literal string are read as PDFDocEncoding and render as mojibake, and a raw CR or CRLF is folded into a single LF (ISO 32000-1 section 7.3.4.2). The hex form has neither problem.

Methods

encode()

Encode a text value as a PDF string token.

public static encode(string $text, int $objectId, callable|null $encoder = null): string

Parameters:

  • $text (string)
  • $objectId (int)
  • $encoder (callable|null): fn(string $text, int $objectId): string

Returns: string

Throws:

  • Exception: If the encoder returns a non-string value.

Source: src/Output/PdfString.php:64