2

我目前正在尝试使用该Zend_Pdf::load($filename)方法加载 PDF 文档,我得到了

Error occured while 'xxx.pdf' file reading.

所以我在 Zend_Pdf_Parser::_construct 看到有这个块

while ($byteCount > 0 && !feof($pdfFile)) {
   $nextBlock = fread($pdfFile, $byteCount);
   if ($nextBlock === false) {
        require_once 'Zend/Pdf/Exception.php';
        throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
   }
   $data .= $nextBlock;
   $byteCount -= strlen($nextBlock);
}
if ($byteCount != 0) {
   require_once 'Zend/Pdf/Exception.php';
   throw new Zend_Pdf_Exception( "Error occured while '$source' file reading." );
}

调试后,我可以说strlen($nextBlock)没有返回正确的值(基于$nextBlock = fread($pdfFile, $byteCount);)如果我mb_strlen($nextBlock,'8bit')改用这个块,则正确传递。现在我收到另一个错误

Pdf file syntax error. 'startxref' keyword expected

所以现在我查看 Zend_Pdf_StringParser:readLexeme() 并且我可以再次看到单字节与多字节字符串函数(strlen 等)存在问题

那么有没有人知道 Zend_Pdf 发生了什么,如果这是一般错误或者我只是错过了一些东西?

4

2 回答 2

0

我遇到了同样的错误,结果证明是 Zend Guard 中的一个错误。显然,我的 PHP 编码器版本将字符串文字中的 ASCII NP 换页符 (\f) 转换为反斜杠 (\)f 字符 (\\f)。

的混淆版本

print bin2hex("\f");

输出

5c66

而不是预期的

0c

此行为导致 Zend_Pdf_StringParser 在 readLexeme 中解析 'startxre' 而不是 'startxref',从而导致您描述的错误。

如果您使用的是不同版本的编码器或根本没有编码器,那么这可能不是问题的原因(尝试在不同的 PHP 版本上重现它)。

于 2012-02-14T07:30:17.930 回答
0

我从未使用过 Zend_PDF,因为它的潜力很小。我建议您将其集成到您的项目TCPDF中!;)

于 2011-10-19T08:27:29.993 回答