Open philipnjuguna66 opened 5 years ago
$parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile('/your/pdf/file');
$images = $pdf->getObjectsByType('XObject', 'Image');
foreach( $images as $image ) {
echo '<img src="data:image/jpg;base64,'. base64_encode($image->getContent()) .'" />';
}
@philipnjuguna66 is your question answered?
image is FlateDecode?? no save
image is FlateDecode?? no save
What do you mean?
is your question answered?
I agree. If there is no feedback soon, I will close for now.
require '../composer/vendor/autoload.php'; use Smalot\PdfParser\Parser; use Smalot\PdfParser\XObject\Image; $parser = new Parser(); $pdf = $parser->parseFile('mipdf.pdf');
$i = 0; $xobjects = $pdf->getObjectsByType('XObject'); foreach ($xobjects as $xobject) { if ($xobject instanceof Image) { $content = $xobject->getContent(); if ('FlateDecode' === $xobject->getHeader()->getElements()['Filter' ]->getContent()) { $content = zlib_decode($content,); //no save here //ERROR CODE: HERE!! PLEASE NO DECODE IMAGEN! } file_put_contents("extraidas/". ++$i .".png", $content); } }
$content = zlib_decode($content,); //no save here //ERROR CODE: HERE!! PLEASE NO DECODE IMAGEN!
I still don't understand what exactly the problem is. What do you mean with save and decode? Please describe it a bit and don't just paste some unformatted code, not helpful.
Okay! when I extract the images from a pdf, there are several that are not detected. Because they are inflated or encrypted, according to what I read I must pass them through a function like zlib_decode but this one, nor the other similar ones in php, returns the image to me, I always get an error code, I
uploaded the same pdf to some extraction pages and they return fine the image I need. Sorry not if I explain it well. I leave a reference link: https://stackoverflow.com/questions/59374914/how-to-extract-images-from-pdf-using-php
Okay! when I extract the images from a pdf, there are several that are not detected. Because they are inflated or encrypted, according to what I read I must pass them through a function like zlib_decode but this one, nor the other similar ones in php, returns the image to me, I always get an error code, I uploaded the same pdf to some extraction pages and they return fine the image I need. Sorry not if I explain it well. I leave a reference link: https://stackoverflow.com/questions/59374914/how-to-extract-images-from-pdf-using-php
Reference link is not working, plz provide some relatable resource for the same for better understanding
Undefined type 'Image'
above error is being shown for your code
$content = zlib_decode($content,); //no save here //ERROR CODE: HERE!! PLEASE NO DECODE IMAGEN!
I still don't understand what exactly the problem is. What do you mean with save and decode? Please describe it a bit and don't just paste some unformatted code, not helpful.
The problem is, When I try to extract images that are PNG formatted, they can't be extracted. PNG images that are FlateDecoded become corrupted and unreadable.
How do i extract images from pdf also if the table contains a table extract the same with styles