Comments (6)
Without you showing any of your code it's hard to debug this issue.
Please take a look at our readme so see how you can detect the amount of pages and how you can create an image per page.
from pdf-to-image.
remote pdf url +1
from pdf-to-image.
I have the same problem, my pdf has 65 pages and in one image is printed all pages
My code:
$pdf = new Spatie\PdfToImage\Pdf($pdfUrl);
$pdf->saveAllPagesAsImages('images');
There is any solution for that ?
from pdf-to-image.
I'm facing the same issue, this code was working fine but now it's only converting the first page into an image.
if (\request()->hasFile('file') && \request()->file('file')->isValid()){
$pdf_name = time().'.pdf';
\request()->file->storeAs('pdf-docs',$pdf_name);
if (file_exists(storage_path('app/pdf-docs').'/'.$pdf_name)){
$pdf = new Pdf(storage_path('app/pdf-docs').'/'.$pdf_name);
$pages = $pdf->getNumberOfPages();
// dd($pages); // this always gives 1
for ($i = 1; $i <= $pages; $i++){
$filename = storage_path('temp/'.time().'pdf-docs.jpg');
$pdf->setPage($i)->saveImage($filename);
$resource->addMedia($filename)->toMediaCollection($collection);
}
}
}
from pdf-to-image.
$pages = $pdf->getNumberOfPages();
// dd($pages); // this always gives 1
I had the same problem only to realize the version I was outdate and on the getNumberOfPages
function it was hardcoded to return 1 only. So I installed a specific version. Try version 2.0.1
composer require spatie/pdf-to-image:2.0.1
Make sure you have PHP extension for Imagick
from pdf-to-image.
change the saveAllPagesAsImage like below
public function saveAllPagesAsImages(string $pathToImage, string $file_name = ''): string
{
$numberOfPages = $this->getNumberOfPages();
$data = "";
if ($numberOfPages > 0) {
$img = new Imagick();
for( $i = 1; $i <= $numberOfPages; $i++ )
{
$this->setPage($i);
$img_path = $pathToImage.DIRECTORY_SEPARATOR.explode(".",$file_name)[0].$this->page.'.'.$this->outputFormat;
$im_dt = $this->getImageData($img_path);
$img->addImage($im_dt);
}
$img->resetIterator();
$combined = $img->appendImages(true);
$img->destroy();
$combined->writeImage($pathToImage.DIRECTORY_SEPARATOR.$file_name);
$combined->destroy();
return $pathToImage.DIRECTORY_SEPARATOR.$file_name;
}
}
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.