pauln / tcpdi_parser

Parser for use with TCPDI, based on TCPDF_PARSER
GNU Lesser General Public License v3.0
27 stars 47 forks source link

Illegal string offset warnings #24

Open tommynovember7 opened 6 years ago

tommynovember7 commented 6 years ago

If a pdf has such an object like the followings, tcpdf_parser fails to continue parsing the data.

2 0 obj
<< /Type /Page % 1
   /Parent 1 0 R
   /MediaBox [ 0 0 839.314286 1186.971429 ]
   /Contents 4 0 R
   /Group <<
      /Type /Group
      /S /Transparency
      /I true
      /CS /DeviceRGB
   >>
   /Resources 3 0 R
>>

getRawObject() is expected to return an array which contains an object and its offset, but it currently returns an object without its offset if the pdf has % comments. It causes Illegal string offset warnings.

https://github.com/pauln/tcpdi_parser/blob/c7c3e86cd1a15c293ae8246d32caaae3e8b27db6/tcpdi_parser.php#L725

I've created a compact example. Would you please check it? tcpdi_parser_issue.tar.gz

$ ls
sample.php  source.pdf  tcpdi_parser
$ php sample.php
PHP Warning:  Illegal string offset 'Parffo' in /Users/lancelot/Sandbox/PHP/tcpdi_parser_issue/tcpdi_parser/tcpdi_parser.php on line 712
PHP Warning:  Illegal string offset 'Parffp' in /Users/lancelot/Sandbox/PHP/tcpdi_parser_issue/tcpdi_parser/tcpdi_parser.php on line 712
PHP Warning:  Illegal string offset 'Parffq' in /Users/lancelot/Sandbox/PHP/tcpdi_parser_issue/tcpdi_parser/tcpdi_parser.php on line 712
...

Additionally, I've created a PR. I'll be grateful if you'd review it.

https://github.com/pauln/tcpdi_parser/pull/23

mrpamacs commented 5 years ago

I have the same problem. Did you find a solution?

tommynovember7 commented 5 years ago

@mrpamacs Actually I already created the PR for the issue, but it still haven't been merged. You might want to fork the repository and apply that change If you want to resolve the issue as soon as possible.

brunobmorais commented 4 years ago

Some PDF files TCPDI cannot read image