Reproduction
Convert file tekst2.zip using:
$rtf = file_get_contents('tekst2.rtf');
$document = new Document(rtrim($rtf, "\0")); // remove ASCII 0, the NULL-byte.
$formatter = new HtmlFormatter('UTF-8');
$html = $formatter->Format($document);
This will throw an exception:
iconv(): Detected an incomplete multibyte character in input string at /.../public_html/vendor/henck/rtf-to-html/src/Html/HtmlFormatter.php:375
Analysis
- On the first line "{\f1\fswiss\fcharset128 Wingdings;}" the WingDings font is defined with fcharset 128.
- fcharset 128 is the Japanese Shift-JIS multibyte font. When the first character has a code of 128 or higher, the total character is compromised of two bytes.
- HtmlFormatter.php is unware of the multibyte CP932 codepage. And calls DecodeUnicode() with only one character. iconv() then throws an exception, because only the half of the multibyte character was provided.
Reproduction
Convert file tekst2.zip using:
This will throw an exception:
Analysis