Skip to main content

decode_text_string

Function decode_text_string 

Source
pub fn decode_text_string(bytes: &[u8]) -> String
Expand description

Decodes a PDF text string (§7.9.2.2) to Unicode.

  • Bytes starting with FE FF are UTF-16BE. Unpaired surrogates and a trailing odd byte become U+FFFD; language escape sequences (U+001B, a language code, U+001B, §7.9.2.2.1) are removed.
  • Bytes starting with EF BB BF are UTF-8 (PDF 2.0); invalid sequences become U+FFFD.
  • Anything else is PDFDocEncoding. An undefined code (a C0 control other than tab, line feed and carriage return, 0x7F, 0x9F, 0xAD) keeps its own scalar, U+0000–U+00FF, as pdf.js, qpdf and pypdf read it: nothing is lost, and a caller that shows the text can drop control characters (ADR 0003 §1).

Never fails: text strings are display data, and a damaged one is still worth showing.

Added in 0.2.0.