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

Embedded png image cannot be parsed #749

Open
cyril-fsm opened this issue Dec 5, 2024 · 3 comments
Open

Embedded png image cannot be parsed #749

cyril-fsm opened this issue Dec 5, 2024 · 3 comments
Labels

Comments

@cyril-fsm
Copy link

  • 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) .'" />';
		}
	}
}
@k00ni
Copy link
Collaborator

k00ni commented Dec 6, 2024

What is the error?

@k00ni k00ni added the bug label Dec 6, 2024
@cyril-fsm
Copy link
Author

Thank you for your reply. The message is :
Warning: zlib_decode(): data error in ...

@cyril-fsm
Copy link
Author

Hello, has anyone had the same problem? A solution? Thanks

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

2 participants