0

I was trying to convert PDF to image. Tried using spatie/pdf-to-image

$pdf = new PDF(public_path('approvedprocess-docs/working_files/5e94d32f99505.certificate.pdf'));
$pdf->saveImage(public_path('approvedprocess-docs/working_files/5e94d32f99505.certificate.jpg'));

Tried using org_heigl/ghostscript

    // Create the Ghostscript-Wrapper
    $gs = new Ghostscript ();
    // Set the output-device
    $gs->setDevice('jpeg')
    // Set the input file
       ->setInputFile(public_path('approvedprocess-docs/working_files/5e94d32f99505.certificate.pdf'))
    // Set the output file that will be created in the same directory as the input
       ->setOutputFile('output')
    // Set the resolution to 96 pixel per inch
       ->setResolution(96)
    // Set Text-antialiasing to the highest level
       ->setTextAntiAliasing(Ghostscript::ANTIALIASING_HIGH);   

Both case getting error:

InvalidArgumentException
No GS-Path set

My ImageMagick and ghostscript is working fine from cmd command line. So how I can set the gs path?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ZahiD
  • 1
  • 4
  • You may need to edit the Imagemagick delegates.xml file to add the full path to `gs` in the PS/PDF line. Also you may need to edit the Imagemagick policy.xml file to give permission for Imagemagick to read PDF files. See https://stackoverflow.com/questions/52861946/imagemagick-not-authorized-to-convert-pdf-to-an-image/52863413#52863413 – fmw42 Apr 14 '20 at 17:35
  • i think delegates.xml file is ok cause when i try to directly use cmd and convert the pdf to image its working. same its also reading the pdf file ok if i triy to use cmd directly. i think its something to do wit gs. i have to some how show the path. but dont know how. – ZahiD Apr 14 '20 at 18:12
  • Laravel as with PHP probably uses a different set of Environment variables. So it cannot find the path to Ghostscript. In PHP, one has to put the full path in front of `gs` in the PS/PDF entry in the delegates.xml file. That typically fixes the issue. I suspect you have the same issue. – fmw42 Apr 14 '20 at 19:33
  • ok that make sense . but i dont know how to add the "full path in front of gs in the PS/PDF entry in the delegates.xml file." . can you share me a example. sorry for being amateur. – ZahiD Apr 14 '20 at 19:58
  • Find the delegates.xml file on your system (not in the install directory). https://imagemagick.org/script/resources.php for locations. Find where your Ghostscript is installed on your system. Then edit the delegates.xml file and insert the path in front of `gs` in all the lines that have `gs` such as ` `. – fmw42 Apr 14 '20 at 20:46
  • sadly not working . I did as you said. – ZahiD Apr 15 '20 at 13:33
  • Did you also edit the policy.xml file to give read|write permission for PDF – fmw42 Apr 15 '20 at 17:24
  • OK i made it work in a quite unorthodox way. I go to vendor>org_heigl and provided defined my gs path variable there. and it worked . – ZahiD Apr 15 '20 at 19:14

0 Answers0