8

I'm trying to convert pdf to jpg using ImageMagick php. It seems that ImageMagick needs Ghostscript to work with pdfs however my shared hosting provider does not allow the installation of Ghostscript since it makes use of shell_exec() and exec().

So my question is. Can I convert pdf to jpg with ImageMagick without Ghostscript. If not is there an alternative. I'm doing this using the wordpress platform fyi.

Dan
  • 9,391
  • 5
  • 41
  • 73
ion
  • 1,033
  • 2
  • 16
  • 46
  • There may be a web service for this, but it's probably best to avoid free ones, since I imagine you'll come to rely on this, and you want to be able to be sure the service will come with reasonable guarantees of availability. – halfer Feb 05 '13 at 14:24
  • has anyone looked into creating a safe version of ghostscript? I dont have the source handy but I can imagine those calls are related to the interactive shell or other things not needed for batch file conversion. @ion if that route would work you might want to pose it as a new question. – agentp Feb 08 '13 at 15:33
  • what about using PDF.js on the client's side - render it to canvas and resend it to php? – rostok Sep 19 '14 at 12:23
  • Have you looked at MuPDF? http://mupdf.com – Mark Setchell Sep 24 '14 at 08:52
  • Using Imagemagick doesn't necessarily require exec(). Imagick has a PHP module so you can use it within php, which many people have success with. – hessodreamy Jul 07 '15 at 08:21

1 Answers1

5

PDF is not a raster image format it is a special language to describe an image. So to convert it to the raster format you need a RIP (Raster image processor).

ImageMagick uses GhsotScript for that. So you can't do it with ImageMagick without GhostScript. You can use GhostScript to render PDF to JPG from command line running gswin32.exe (even without ImageMagic) or from your software using gsdll32.dll.

Also another way is to use Adobe ActiveX component from your software. Usually it is already installed on Windows with Adobe Acrobat.

Here is a good explanation and many ways to render PDF

Community
  • 1
  • 1
valex
  • 23,966
  • 7
  • 43
  • 60
  • 2
    Thanks for the info but I'm looking for a php solution that can perform the conversion either on pageload or when the image is uploaded to wordpress – ion Feb 05 '13 at 15:34
  • Here's a good blog on how to do this http://bertanguven.com/faster-conversions-from-pdf-to-pngjpeg-imagemagick-vs-ghostscript/ – Reza S Mar 26 '15 at 00:27