Comments (10)
You loop through the PDF pages to save each page individually.
for ($i = 1; $i <= $pdf->getNumberOfPages(); $i++) {
$pdf->setPage($i)->setOutputFormat('png')->saveImage('path/to/image.png');
}
You can in turn also decide yourself what page number you want to save.
$i = 1;
$pdf->setPage($i)->setOutputFormat('png')->saveImage('path/to/image.png');
from pdf-to-image.
Try this ;-)
#13
from pdf-to-image.
Probably something to do with transparency yes...
I'd accept a PR that fixes this.
from pdf-to-image.
Figured this happens when the PDF has multiple pages and you try to save it without looping through the pages.
from pdf-to-image.
HI,
Yes I'm facing the same issue i have multiple pages pdf file, when i convert it, it give me black background instead of white, any solution so far ?
Thanks
Adil
from pdf-to-image.
Thanks for this, that i have already did, but can't save single image with all pages images is there any way for this.
Thanks for your help so far.
from pdf-to-image.
i did a short look, and as i can see Imagick is used, try to use
flattenImages(); that should do the trick
from pdf-to-image.
flattenImages() was just removed as i can see, now it's
$image->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
from pdf-to-image.
Same issue persists (transparent background) when trying to save as PNG
was able to fix by forcing this:
Pdf.php:
public function getImageData($pathToImage) {
...
$imagick->transparentPaintImage('#FFFFFF',1,1, 'normal'); // added this
$imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
...
}
fyi: http://phpimagick.com/Imagick/transparentPaintImage
from pdf-to-image.
Closing this for now, I accept PR's that make this package more stable.
from pdf-to-image.
Related Issues (20)
- Multiple pages overlapped into one image when pdf is loaded from url HOT 4
- PHP 8 compatibility HOT 2
- Call to undefined method Spatie\PdfToImage\Pdf::setCompressionQuality() HOT 5
- Support for PHP 8.1 HOT 4
- PDFDelegateFailed `The system cannot find the file specified. ' @ error/pdf.c/ReadPDFImage/794 http://localhost:8000
- Spatie\PdfToImage\Exceptions\PdfDoesNotExist HOT 1
- PDF with Annotations? HOT 1
- "Pdf::setCompressionQuality()" HOT 3
- Image has a black background color HOT 4
- getNumberOfPages returns wrong number HOT 3
- Image size (width and height) issue HOT 2
- Support for php 8.x HOT 2
- After converting, the file does not open anymore. Message: Something went wrong. HOT 1
- imagick extintion dose now work HOT 7
- FailedToExecuteCommand when trying to ping PDF file HOT 5
- Webp support HOT 2
- Tag new release HOT 6
- " Class 'Imagick' not found" how to solve HOT 3
- Feature request HOT 1
- Text convertion broke
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdf-to-image.