Embedded png image cannot be parsed
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
- PHP Version: 7.4.11
- PDFParser Version: 2.11
Description:
Hello, I am trying to parse a pdf that contains png images but I can't do it. The content of the image seems corrupted which triggers an error with zlib_decode
Thanks for your help
PDF input
https://telechargements.soludedia.fr/divers/LF6451.pdf
Expected output & actual output
Code
if ($f = file_get_contents('file.pdf')) {
include "./inc/pdfparser-2024/alt_autoload.php";
$parser = new \Smalot\PdfParser\Parser();
$document = $parser->parseContent($f);
$pages = $document->getPages();
$page = $pages[0];
$content = $page->getText();
$images = $document->getObjectsByType('XObject', 'Image');
foreach($images as $index=>$image) {
$img_content = $image->getContent();
$details = $image->getHeader()->getDetails();
if ('FlateDecode' === $image->getHeader()->getElements()['Filter']->getContent()) {
$img_content = zlib_decode($img_content);
echo '<img src="data:image/png;base64,'. base64_encode($img_content) .'" />';
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the linked LF6451.pdf and the provided parseContent, getObjectsByType, getContent, and getHeader calls. Inspect how FlateDecode image XObjects are exposed before the caller invokes zlib_decode. Done means the embedded PNG content can be parsed without the reported zlib error, with a regression test for the supplied PDF if the project supports one.
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
- 32/100