0

I am trying to use the script from Paolo Bergantino How do I convert a PDF document to a preview image in PHP? After my hosting has installed the Imagick I am now struggling to get the code working.

What I see is a raw image with lots of questionmarks being generator with ImageMagick and GhostScript.

raw image data

$im = new imagick('Maps.pdf[0]');
$im->setImageFormat('jpg');
//header('Content-Type: image/jpeg'); (updated ro remove header error)
echo $im;de

What am I doing wrong? Jan

SOLVED: by solving the header problem (extra white spaces) the image is shown!

Community
  • 1
  • 1
Gitaartabs
  • 37
  • 1
  • 10
  • you are getting php error. This is because you left some enter at the end of one page. that is head.inc.php remove that extra enter hope this will solve your problem – Aman Rawat May 18 '15 at 13:52
  • @AmanRawat I have checked the "enter" but I do not really understand what you mean. After the bracket all my script ends with `} ?>` But I did textmark the `//header('Content-Type: image/jpeg');` which results in no header error anymore but the questionmarks are still there. – Gitaartabs May 18 '15 at 14:17
  • dont use } ?> use } if there is no html at the bottom of page and do not print anything before redirection – Aman Rawat May 18 '15 at 15:51
  • @AmanRawat I'm looking for a solution for the questionmarks, not for the headers as Danack mentioned. Any suggestions on that? – Gitaartabs May 19 '15 at 19:17
  • 1
    Actually these question marks are because your pdf is broken because of some extra text which is printed by the php error. So if you resolve that error hope it will work. The error is because there is some extra enter in one of the php page. Recheck for that and remove those extra space. Hope it will work. Check both files header.inc.php and view/table2.inc.php and remove extra enter and space if any. Don't print anything before redirection – Aman Rawat May 20 '15 at 07:30
  • @AmanRawat Thanks, I tested it with a blank page. There it works so now i have to solve the header problem. Thumb up! – Gitaartabs May 21 '15 at 20:53

0 Answers0