smalot / pdfparser

PdfParser, a standalone PHP library, provides various tools to extract data from a PDF file.
GNU Lesser General Public License v3.0
2.37k stars 538 forks source link

Chinese text problems #664

Open micos7 opened 9 months ago

micos7 commented 9 months ago

Description:

PDF input

在历史的风陵渡口 (高华) (Z-Library).pdf

Expected output & actual output

I get an avalanche of weird characters Ex: \nµ¡úÕ╝ÅÕ«úÕ©âÕ╝ÇÕ▒òÞé⵩àÕ£░õ©╗Õ»îÕå£þÜäµûùõ║ëÒÇéÚÇÜÕæèµîçÕç║´╝ÜÞÁúÞÑ┐ÕìùÕàÜÕåൣëõ©Çõ©Ñ\nÚçìþÜäÕì▒µ£║´╝îÕì│Õ£░õ©╗Õ»îÕå£ÕààÕí×ÕàÜþÜäÕÉäþ║ºÕ£░µû╣µîçÕ»╝µ£║Õà│´╝îÕàÜþÜäµö┐þ¡ûÕ«îÕà¿\nµÿ»µ£║õ╝Üõ©╗õ╣ëþÜäµö┐þ¡û´╝îÞïÑõ©ìÕ¢╗Õ║òÞé⵩à´╝îõ©ìõ¢åõ©ìÞ⢵ëºÞíîÕàÜþÜäõ╝ƒÕñºþÜäµö┐µ▓╗\nõ╗╗Õèí´╝îÞÇîõ©öÚØ®Õ梵á╣µ£¼ÞªüÚü¡Õñ▒Þ┤ÑÒÇéÞüöÕ©¡õ╝ÜÞ««ÕÅÀÕżÕàÜÕåàÚØ®Õæ¢ÕÉîÕ┐ùÞ

Code

$pdf = $parser->parseFile(storage_path('app/'.$path)); dd($pdf->getText());

I`m on Ubuntu 22,I have the chinese language installed. Thanks for your work!

GreyWyvern commented 8 months ago

There are are quite a few places in this document where small sections of text aren't being decoded properly, but for me in 2.8.0-RC2 the vast majority of Chinese text is coming through fine. Some sample:

在历史的风陵渡口 年以来的路线。 毛泽东已看到经济形势全面趋向好转,他心中有数,虽然还有” 非正常死亡“,但最危急的时期已经过去。蒋介石在 1962年夏叫 嚷反攻大陆,但蒋的底线毛完全掌握,毛、周急电参加中美大使级 会谈的中方代表王炳南飞京,再返华沙向美国大使摸底,知肯尼迪 政府反对蒋介石反攻大陆,所以当陈云以对付蒋反攻为由,要求毛 批准分田到户(刘、周、邓均同意陈云的意见),毛根本不能接受。 [104] 因此,1962年上半年,毛开始将其态度逐渐明朗化。 1、毛不 同意周在广州会议上的讲话,即使周多次请毛表态,他就是不答复。 毛得到政治局候补委员、副总理、中宣部部长陆定一的支持,陆虽 然私下对大跃进有异议,但在人民公社和对知识分子的看法上与毛 基本一致。 [105]2、毛不同意实行包产到户,虽然刘、周、邓、陈 都倾向于支持邓子恢的意见,但陶铸、胡耀邦等党内许多高干都对 包产到户持反对意见,甚至连彭德怀也反对。 3、在毛的影响下, 党内刊物大量刊载歌颂斯大林的文字。1962 年上半年,毛基本住 在南方,密切注视着刘等的一举一动,他守住底线,准备反击。 1961- 62年,刘少奇因力主实事求是,正视困难,其个人威 望得到大幅提高,尽管刘具事实正确,却因毛独享”解释权“,而 不具意识形态的”正确性“。刘在 1962年春之后,同意”三自一 包“,但只是私下流露而未有自己的解释,刘只能默认地方悄悄干, 不是”光明正大“。毛却师出有名,名正言顺,因为从 1961年以 来,党内的主流意见一直是批判三自一包,刘自己长期也是持这种 观点。1962 年的”七千人大会“,其议题之一即是批评”三自一 包“,会后中央明令安徽省委取消”单干“。 2月,新任安徽省委 第一书记李葆华在省常委会议讲话,转达刘少奇对安徽责任田的意 见,刘认为责任田”要走回头路,这是很明确的“。 [106]3月,北 京已在内部批评湖南 5县”刮分田黑风“。[107] 刘少奇已将自己 置放于一个尴尬的境地。 刘主持对过往政策的全面调整,但八届九中全会要求, ”进行 206 页眉:禁书网 �K�W�W�S����Z�Z�Z��E�D�Q�Q�H�G�E�R�R�N��R�U�J� 禁片禁闻网大陆直连: �K�W�W�S����W�L�Q�\��F�F��P�H�\�D�U�Z

Perhaps the default encoding of the page which the OP is using to display the output is set to a Chinese specific encoding instead of UTF-8? PdfParser outputs content in UTF-8 despite what the internal encoding is.

micos7 commented 8 months ago

I don`t have a page output it`s a die and dump in a laravel job, the output is in the terminal.

fishfree commented 4 months ago

@GreyWyvern I changed to 2.8.0-RC2, the problem still exists.

GreyWyvern commented 4 months ago

I'm guessing this is probably CLI issue, because the OPs document decodes mostly fine for me (with the small decoding errors above as shown). If you're having an issue with Chinese text displaying improperly in browser output, then you should report it as a different issue. Do you have an example document of your own?

fishfree commented 4 months ago

news.pdf @GreyWyvern Thank you for your response. This is the test PDF file.