0

I need the uploaded pdf to be converted to one long png image. Simple images (e.g. jpg) works fine and also pdf do if i just convert the last page (default). However when a try to convert all the pages of the pdf into one png it produces a long black image or a long black image with a white strip.

if ($file === null || !($file instanceof UploadedFile)) {
        throw new \LogicException('No uploadable file found');
    }
    $tmpFile = $file->getRealPath();

    try {
        $im = new \imagick();
        $im->pingimage($tmpFile);
        $im->setresolution(140, 140);
        $im->readimage($tmpFile);

        switch ($file->getMimeType()) {               
            case 'application/pdf':
                $im->resetIterator();
                $ima = $im->appendImages(true);
                $ima->setImageFormat('png');
                $ima->writeImage();
                $ima->clear();
                $ima->destroy();
                break;
            default:
                break; //return new Response('error');
        }
Danack
  • 24,939
  • 16
  • 90
  • 122
fagyi
  • 93
  • 2
  • 8

1 Answers1

0

Well i figured out the problem..may somebody will need this. I dont know why and how but the pingimage() method caused the problem. Very interesting imo that it actually not make any problem if (by default) i want to convert only one page of the pdf or not multipaged images. As soon as i removed that method the produced image was correct. Also note that i use windows 8 and havent tried it on linux. May this method doesnt make any problem on linux.

fagyi
  • 93
  • 2
  • 8