pub fn encode_text_string(text: &str) -> Vec<u8> ⓘExpand description
Encodes text as a PDF text string (§7.9.2.2), the inverse of decode_text_string:
PDFDocEncoding when every character has a code, else UTF-16BE with a FE FF byte
order mark. PDFDocEncoding output that would start with a byte order mark (þÿ, )
is written as UTF-16BE too, so it never decodes as something else. U+001B (ESC) is
written as U+FFFD: in UTF-16BE it brackets a language code (§7.9.2.2.1), so a literal
ESC could make a reader drop the text after it.
use laminapdf_syntax::text::{decode_text_string, encode_text_string};
assert_eq!(encode_text_string("Café €"), b"Caf\xE9 \xA0");
assert_eq!(encode_text_string("中"), b"\xFE\xFF\x4E\x2D");
assert_eq!(decode_text_string(&encode_text_string("Grüße, 世界")), "Grüße, 世界");Added in 0.2.0.