mfenniak/pyPdf — Issue #37: Fail to read a text object
Author: tdiwasa
Created: 2011-12-15 06:44:12+00:00
State: open

readStringFromStream() fails to create a string object
if a text object like below was given.

BT 1 0 0 1 0 1.9 Tm /F3+0 8.6 Tf 10.5 TL (\376\377 ) Tj T* ET

readStringFromStream() decodes (\376\377 ) to a string '\xfe\xff\x20'.

createStringObject() checks first 2 bytes of the string,
and will attempt to decode with UTF-16.
Then an exception will be raised because '\x20' is illegal as UTF-16.

Apparently, a text "\376\377" should not be treated as BOM.

BOM check would be a conformance of "Text Strings" described in PDF Reference,
but it should be applied only to the "text string" type item specified in PDF Reference.