smalot / smalot/pdfparser

Problems with getText() on PDF documents with UTF16BE encoding

Open
#734 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug de-/encoding issue
Dominant language
PHP
Stars
2.7k
Forks
579
Avg merge
2m
Merged PRs (30d)
1

Description

  • PHP Version: 8.2
  • PDFParser Version: 2.11.0
Description:
PDF input

There is a file attached to a bug report of pdftotext https://gitlab.freedesktop.org/poppler/poppler/-/issues/332

2004.pdf

Expected output & actual output

The getText() output returns mostly utf16 encoding text, but it seems like there were non utf16 chars added by the parser.
Besides that, I wonder if there is any way to determine which encoding is use? Or maybe, can the parser do a conversion to utf8?

Code

$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($infile);
$t = $pdf->getText();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the report with the attached 2004.pdf, PHP 8.2, PDFParser 2.11.0, and the shown Parser::parseFile() and getText() calls. Compare the returned text with the PDF content and investigate how encoding is detected or converted; the issue does not identify a file or test, and the expected behavior needs clarification.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.