smalot / smalot/pdfparser

Invalid object reference for $obj.

Open
#770 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  • PHP Version: 8.0
  • PDFParser Version: 2.12.0
Description: With this PDF I get this error: "Invalid object reference for $obj." on line 544 of the file RawDataParser.php
PDF input

gráfico anual collado.pdf

Expected output & actual output

The text of the file

Code

$parser = new \Smalot\PdfParser\Parser();

// Leemos el PDF
try {
$config = new \Smalot\PdfParser\Config();
$config->setIgnoreEncryption(true);
$pdf = $parser->parseFile($pdfGenCu_FicheroTemporalRecibido, $config);

// Sacamos el texto y por si acaso, lo pasamos todo a mayúsculas
$contenidoPDF = $pdf->getText();
$contenidoPDF = strtoupper($contenidoPDF);
// Vamos a quitar los dobles espacios si hubiera
$contenidoPDF = preg_replace('/\s\s+/', ' ', $contenidoPDF);

} catch (Exception $e) {
$alert_text = 'Error al procesar el PDF: ' . $e->getMessage();
if (method_exists($e, 'getLine') && $e->getLine() !== null) {
$alert_text .= ' en la línea ' . $e->getLine();
}
if (method_exists($e, 'getFile') && $e->getFile() !== null) {
$alert_text .= ' en el fichero ' . $e->getFile();
}
}

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 at RawDataParser.php line 544 and reproduce the failure with the attached PDF using PHP 8.0 and PDFParser 2.12.0. Compare the parser's behavior with the provided parsing snippet and verify that the PDF's text can be extracted without the “Invalid object reference for $obj.” error.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.