Code Monkey home page Code Monkey logo

Comments (6)

freekmurze avatar freekmurze commented on May 24, 2024

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.

 avatar commented on May 24, 2024

remote pdf url +1

from pdf-to-image.

dawiddczaja avatar dawiddczaja commented on May 24, 2024

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.

mohsinalandsterling avatar mohsinalandsterling commented on May 24, 2024

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.

mtuchi avatar mtuchi commented on May 24, 2024

$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.

 avatar commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.