0

I want to create image of the first page of an PDF file. So for that I followed the instruction from this link- Install Imagick for PHP and Apache on Windows

All steps I have completed successfully as shown above link. Then I wrote my php code which is as follow-

<?php 

   try{

     $im = new Imagick();
     $im->setResolution(300,300);
     $im->readImage('mypdf.pdf[0]');
     $im->scaleImage(1000,0);
     $im->setImageFormat('jpg');
    //$im->setImageCompression(imagick::COMPRESSION_JPG); 
     $im->setCompressionQuality(100);
     $im = $im->flattenImages();
    $im->writeImage('test.jpg');
  }

  catch(Exception $e) {
     echo 'Message: ' .$e->getMessage();
   }
?> 

and I got following error --

Message: PDFDelegateFailed `[ghostscript library 9.16] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300" -dFirstPage=1 -dLastPage=1 "-sOutputFile=C:/Windows/TEMP/magick-4220l9dSVismOfxn%d" "-fC:/Windows/TEMP/magick-4220xKPtbptSyL7t" "-fC:/Windows/TEMP/magick-4220niNseKCMcRtD"': Error: /undefinedfilename in (C:/Windows/TEMP/magick-4220xKPtbptSyL7t) Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push Dictionary stack: --dict:1200/1684(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)-- Current allocation mode is local Last OS error: No such file or directory GPL Ghostscript 9.16: Unrecoverable error, exit code 1 @ error/pdf.c/InvokePDFDelegate/271

Now I cant understand what is going wrong there. How it will be fixed so I am stuck at this stage. So please anyone can help me to sought out this problem.

UPDATE-- I googled about this problem and found one link- Why converting this PDF file fails when using ImageMagick/Ghostscript?

But I could not understand its answer. I am not sure what to do after reading it.

Thanks in advance.

Community
  • 1
  • 1
shashank
  • 566
  • 3
  • 10
  • 31

0 Answers0