Saving Each PDF Page to an Image Using Imagick

后端 未结 4 761
生来不讨喜
生来不讨喜 2020-12-29 07:49

I have the following php function below that\'s converting a local PDF file into images. In short, I want each PDF page to be converted to a separate image.

The func

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-29 08:24

    first install

    imagemagick

    in your system or server and then create

    pdfimage

    folder and put pdf file in this folder then run the code and upload it file

    setImageBackgroundColor('white');
            //$img = $img->flattenImages();
    
            // Set image resolution
            // Determine num of pages
            $img->setResolution(300,300);
            $num_pages = $img->getNumberImages();
    
            // Compress Image Quality
            $img->setImageCompressionQuality(100);
            $images = NULL;
            // Convert PDF pages to images
            for($i = 0;$i < $num_pages; $i++) {         
                $images[]=$basename.'-'.$i.'.jpg';
                // Set iterator postion
                $img->setIteratorIndex($i);
    
                // Set image format
                $img->setImageFormat('jpeg');
    
                // Write Images to temp 'upload' folder     
                $img->writeImage('pdfimage/'.$file_name.'-'.$i.'.jpg');
            }
            echo "
    ";
            print_r($images);
            $img->destroy();
        }
        //}
    ?>
    

提交回复
热议问题