spatie / pdf-to-image

Convert a pdf to an image
https://murze.be/2015/07/convert-a-pdf-to-an-image-using-php/
MIT License
1.32k stars 228 forks source link

No GS-Path set #147

Closed rashidabbas7865 closed 4 years ago

rashidabbas7865 commented 4 years ago

Hi, I'm facing this issue with normal use $pdf = new Pdf(asset('pdf/file.pdf')); $pdf->saveImage(asset('pdf'));

I'm using windows and Xampp. I have installed imagemagick and ghostscript on my windows. What it is the issue now. Please help me. where I set the path.

vincent-ikonk commented 4 years ago

Same error.

rashidabbas7865 commented 4 years ago

Here is my work around to fix this issue and it perfectly worked!

use Spatie\PdfToImage\Pdf; use Org_Heigl\Ghostscript\Ghostscript;

and

Ghostscript::setGsPath("C:\Program Files\gs\gs9.52\bin\gswin64c.exe"); $pdf_url = 'C:\Program Files\public\pdf\file.pdf'; $pdf = new Pdf($pdf_url); $pdf->setOutputFormat('png')->saveImage('rashid%d');

Make sure you have installed imagemagick and ghostscript. And the pdf url must be directory based url. not domain url. Please try this solution. It will surely work. This Video is exactly what I suggested. Please follow it

Khurramxhahzad commented 4 years ago

@rashidabbas7865 can you please help me to fix this issue? I tried it but request in my browser takes too long and nothing happens.

Here is my code... $form = public_path('car_ij_appfrm.pdf'); $pdf = new Pdf($form);

$gs_path = public_path('gs\gs952w64.exe');
Ghostscript::setGsPath($gs_path);

foreach (range(1, $pdf->getNumberOfPages()) as $pageNumber) {
    $file_name = public_path('page'.$pageNumber.'jpg');
    $pdf->setPage($pageNumber)->saveImage($file_name);
}
rashidabbas7865 commented 4 years ago

Have you tried with my way?? Were you able to make it work?

Khurramxhahzad commented 4 years ago

@rashidabbas7865 yes tried your way as well. But its not working due to GS. can you give me few minutes for this ? its a request.

rashidabbas7865 commented 4 years ago

Send me your details.

Khurramxhahzad commented 4 years ago

Skype: khurram.shahzad358 khurramshahzadkhan11@gmail.com

rashidabbas7865 commented 4 years ago

Skype: khurram.shahzad358 khurramshahzadkhan11@gmail.com

This Video is exactly what I suggested. Please follow it