PrawnEx.PDF.Encoder (prawn_ex v0.6.0)

Copy Markdown View Source

Encodes values for PDF output: string escaping, name encoding.

Summary

Functions

Escapes a string for use inside a PDF literal string (parentheses), transliterating UTF-8 to WinAnsi (CP1252) on the way: the base-14 fonts are single-byte, so bullets, dashes, and curly quotes would otherwise come out as mojibake. Unmappable codepoints become ?.

Encodes a PDF literal string: (escaped_content)

Encodes a PDF name (e.g. font resource). Leading / and special chars.

Format a number for PDF (integer or float).

Transliterates a UTF-8 string into WinAnsi (CP1252) bytes: ASCII and Latin-1 pass through, the CP1252 punctuation block (bullet, en/em dash, curly quotes, ellipsis, euro...) maps to its byte, anything else becomes ?.

Functions

escape_string(s)

@spec escape_string(String.t()) :: String.t()

Escapes a string for use inside a PDF literal string (parentheses), transliterating UTF-8 to WinAnsi (CP1252) on the way: the base-14 fonts are single-byte, so bullets, dashes, and curly quotes would otherwise come out as mojibake. Unmappable codepoints become ?.

literal_string(s)

@spec literal_string(String.t()) :: String.t()

Encodes a PDF literal string: (escaped_content)

name(s)

@spec name(String.t()) :: String.t()

Encodes a PDF name (e.g. font resource). Leading / and special chars.

number(n)

@spec number(number()) :: String.t()

Format a number for PDF (integer or float).

winansi(s)

@spec winansi(String.t()) :: binary()

Transliterates a UTF-8 string into WinAnsi (CP1252) bytes: ASCII and Latin-1 pass through, the CP1252 punctuation block (bullet, en/em dash, curly quotes, ellipsis, euro...) maps to its byte, anything else becomes ?.