Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDataTm is not returning all the text #761

Open
ridgey-dev opened this issue Feb 6, 2025 · 3 comments
Open

getDataTm is not returning all the text #761

ridgey-dev opened this issue Feb 6, 2025 · 3 comments
Labels

Comments

@ridgey-dev
Copy link

ridgey-dev commented Feb 6, 2025

  • PHP Version: 8.2.27
  • PDFParser Version: 2.11.0

Description:

PDF input

pdf-with-text.pdf

Expected output & actual output

The PDF contains the word {{signer1}}, but the getDataTm does not return this text for the second page.

[
  [
    [
      "1",
      "0",
      "0",
      "1",
      "36.266",
      "754.031"
    ],
    "Test"
  ],
  [
    [
      "1",
      "0",
      "0",
      "1",
      "34.016",
      "701.653"
    ],
    ""
  ]
]

Note that: The getTextArray is returning {{signer1}}. The problem has to do something with getTextArray returning an empty string for the second page. (Probably because of the image?)

[
  "Test",
  "",
  "{{signer1}}"
]

Code

$parser = new Parser();
$document = $parser->parseContent($content);

foreach ($document->getPages() as $page) {
    foreach ($page->getDataTm() as $value) {
        var_dump($value);
    }
}
@k00ni k00ni added the bug label Feb 6, 2025
@MaheKarim
Copy link

// Extract PDF (Text Based Content)
$parser = new Parser();
$pdf = $parser->parseFile($filePath);
$resumeContent = $pdf->getText();

This works for me

@ridgey-dev
Copy link
Author

ridgey-dev commented Feb 12, 2025

Yup. That is because the getText function contains some trim logic:

if ($text = trim($page->getText())) {

But sadly, I need the position of the text too. So I can't just use the getText function.

Maybe a solution could be to move that check to getTextArray ? I'm not very familiar with that code, so it would be helpful if someone can think about this.

@ridgey-dev
Copy link
Author

ridgey-dev commented Feb 12, 2025

I created a PR to fix this: #762. Can someone take a look at it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants