pdfparser icon indicating copy to clipboard operation
pdfparser copied to clipboard

Wrong Unicode Detection

Open sparx82 opened this issue 10 years ago • 5 comments

Hi

I have a PDF here (generated from my companies SAP system) which has hexadecimal encoded text but IS NOT unicode. This leads to the effect that the output of the parser is Windows-1252 coded text while it should be UTF-8.

Some more details: Font.php line 361 sets $unicode = true for hexadecimal coded text but this is not true for my pdf. If comment this line, my PDF is parsed correctly as the conversion is then done by Font.php line 491.

$this->has('ToUnicode') is false $this->has('Encoding') is true

$encoding = $this->get('Encoding');
if ($encoding instanceof Encoding)

is false

So everything decodeContent should do is encode the text to Unicode but this is prevented by $unicode beeing true.

I don't know the PDF standard well enough to say whether this is a bug in the pdfparser or the PDF is not according to the standard at all.

Unfortunately I cannot attach the PDF because it contains pretty private data and all my attempts to create a similar one using Python failed so far. But I keep trying. And I'm happy to help with debug information if necessary.

sparx82 avatar Mar 04 '16 12:03 sparx82

Ok, I was able to create a PDF which has the same problem.

Stream is <E6F6FC> and it should look like this: image

And this PDF causes the problem: SpecialCharTest.pdf

$unicode is set true because of the hex-encoding but it is not unicode at all.

sparx82 avatar Mar 05 '16 10:03 sparx82

Hi sparx82, Should your patch fix this issue ? Could you update too the unit test classes ? Many thanks for your patch

smalot avatar Apr 05 '16 07:04 smalot

Hi smalot,

I added my test PDF and extended the tests to check for correct decoding of ANSI/Unicode PDF content. The patch should fix the issue, at least as good as the mb_check_encoding PHP function works. Which should be ok according to the comments on the PHP site.

sparx82 avatar Apr 07 '16 06:04 sparx82

Updated pull request: https://github.com/smalot/pdfparser/pull/96

sparx82 avatar Apr 07 '16 06:04 sparx82

Hi! You should close this issue if #96 fixed it.

Golmote avatar Apr 27 '18 12:04 Golmote