fix(forms): decode AcroForm field names and values as PDF text strings
AcroForm /T names and /V values for text and choice fields were read with String::from_utf8_lossy. A value written as UTF-16BE with the FE FF byte order mark (common in forms filled by Acrobat and many generators) came out as ��\0S\0c\0h\0u...: U+FFFD for the mark, a NUL before every ASCII letter, and U+FFFD for each byte of a non-ASCII character such as ß.
They now go through decode_pdf_text_string, the decoder the document information dictionary already uses, which handles UTF-16BE and UTF-16LE with a mark, UTF-8 with or without a mark, PDFDocEncoding otherwise, and drops trailing NUL padding.
Verified on a real 6-page German AcroForm PDF with pdf2md: 101 NUL and 8 U+FFFD characters before, 0 and 0 after, with Raiffeisenstraße 1 and Schulangelegenheiten read correctly. Added a unit test for a UTF-16BE name and value. cargo clippy -- -D warnings and cargo test pass.
Summary by cubic
Fixes AcroForm field names and text or choice values being misread when stored as UTF-16BE with a FE FF byte order mark, which previously produced NUL characters before ASCII letters and U+FFFD for the mark and each non-ASCII byte. They now decode as PDF text strings using the same decoder as the document information dictionary.
- Handles UTF-16BE and UTF-16LE with a byte order mark, UTF-8 with or without a mark, and PDFDocEncoding, and drops trailing NUL padding.
- Adds a unit test covering a UTF-16BE field name and value.