ZF-8791: Error: Pdf file syntax error. 'startxref' keyword expected. Offset - 0x2180.


Zend_Pdf_Parser gives an error on line 440: $this->_stringParser->readLexeme();

The parser works fine on my local Windows XP development machine, but it crashes on my Ubuntu 8.04 Linux server. The code is exactly identical on both machines, and so is the PDF file that I am loading with Zend_Pdf::load().

The error stack is below:

Error: Pdf file syntax error. 'startxref' keyword expected. Offset - 0x2180.

0 /home/mvm_stevens/www_mvm/library/Zend/Pdf.php(303): Zend_Pdf_Parser->__construct('/home/mvm_steve...', Object(Zend_Pdf_ElementFactory_Proxy), true)

1 /home/mvm_stevens/www_mvm/library/Zend/Pdf.php(253): Zend_Pdf->__construct('/home/mvm_steve...', NULL, true)

2 /home/mvm_stevens/www_mvm/application/models/Report/Pdf.php(15): Zend_Pdf::load('/home/mvm_steve...')

3 /home/mvm_stevens/www_mvm/application/controllers/ReportsController.php(102): Report_Pdf->loadTemplate('10_slf_mon1_tem...')

4 /home/mvm_stevens/www_mvm/application/controllers/ReportsController.php(38): ReportsController->createReport(Array)

5 /home/mvm_stevens/www_mvm/library/Zend/Controller/Action.php(513): ReportsController->initialrepAction()

6 /home/mvm_stevens/www_mvm/library/Zend/Controller/Dispatcher/Standard.php(289): Zend_Controller_Action->dispatch('initialrepActio...')

7 /home/mvm_stevens/www_mvm/library/Zend/Controller/Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))

8 /home/mvm_stevens/www_mvm/application/bootstrap.php(56): Zend_Controller_Front->dispatch()

9 /home/mvm_stevens/www_mvm/index.php(11): Bootstrap->runApp()

10 {main}

I outcommented the lines 440 until 453 in Parser.php and echoed the content of $data to the browser, to see if the PDF file is properly read with the 'fread' function, and the output almost identical. The Ubuntu machine seems to recognize more characters. For example, the Windows version showed the following as the 2nd line: %���� and Ubuntu showed: %âãÏÓ

Anybody any ideas what is going on or what I can do to get the Ubuntu server load these PDF files?


I had the same issue. The problem in my case was that i configure mbstring.func_overload to use mbstring functions instead of the normal string functions. Try something like this to see if this is also your problem:

ini_set('mbstring.internal_encoding', 'ASCII'); $pdf = Zend_Pdf::load('my.pdf'); ini_set('mbstring.internal_encoding', 'UTF-8');

mbstring setting didn't help for me

PDF handling worked flawless both with zf 1.5.1 (ubuntu 8.04) and zf 1.9.4 (ubuntu 9.10);

zend 10.1 on ubuntu 8.04 did not work (error as described above), so I went back to 1.5.1 on this machine

Exact same issue as Michael...

Ubuntu 8.04.3 and Zend 10.1

I've encountered the same problem on one domain hosting based on linux. I tried zf 1.5.1 and some versions between 1.5.1 and 10.1 but nothing helped. Zf 1.5.1 displayed another problem than "'startxref' keyword expected" (I haven't written it down) but it also failed.

After some investigation I discovered that code at line 440 $this->_stringParser->readLexeme() is actually expected to read 'startxhref' word from pdf file. But in fact it reads 'startxhre' (without 'f' at the end) so exception is thrown.

We had a similar issue.

On my Windows machine running Zend 1.9.6 and Php 5.2.8 it all worked fine. We then rolled it out to our live systems where it only works on one of the two Ubuntu machines.

I was tasked with figuring out what is happening here. We found that our one system is runnin PHP 5.2.4 and the other is running 5.2.5 both with Zend 1.9.6.

The one running 5.2.5 is working fine but the one with 5.2.4 is giving us the problems.

I then had a look at the StringParser.php. In there you will find that Zend 1.9.6 checks for \f as one of the white space characters. This is not supported in version 5.2.4 yet (http://php.net/ChangeLog-5.php). So I had to go do a version check and adjust the data parser.

You want to go to line 267 and replace it with the following block of code:

$compare = ""; if ( version_compare( phpversion(), '5.2.5' ) >= 0 ) { // this version added support for the escaped form feed character $compare = "()<>[]{}/%\x00\t\n\f\r "; } else { $compare = "()<>[]{}/%\x00\t\n\r "; }

$this->offset += strcspn($this->data, $compare, $this->offset);

Hope this solves your problem.

Thanks a lot, Quintin.

Your fix works great :).

Could this be fixed and backported to 1.9.7 (1.9.8 perhaps?) as the minimum requirement for ZF is PHP 5.2.4 and not PHP 5.2.5.

This is a serious showstopper. Could this PLEASE be fixed ASAP so we don't have to patch StringParser.php ourselves? This fix is here, please apply it.

This patch applies to Zend_Pdf_StringParser of ZendFramework 1.10.4

I'm sorry for spamming this issue, but could this fix be applied before the next mini-release?

Sorry for the delay guys, I'm not a Zend_Pdf maintainer but I noticed your Devzone comment ;). Ask, and thou shalt receive! So I reviewed the patch. Fix looks good so I've applied it in r22311. Worth noting, there are always devs around on our regular bug hunt days - if there are other patches anyone needs applying you can grab us on IRC at those times for assistance.

Will apply this to the release branch soon for next mini-release.

Thanks for resolving this, much appreciated.

Thanks a mil.

Thank you for applying it, Padraic.