Convert file PDF to JPG with PHP


Posted on 2015-04-20 03:01:21


In order to bring beginners of language PHP has more experiences, I would like to share with you a nice feature that gives our PHP. 

This feature will help you convert PDF files into image file format is JPG. 

Just copy the following function, and applied to the purposes of his later:

1
2
3
4
5
6
7
8
9
function pdfToJpg($pdf, $jpg) {
    $im = new Imagick();
    $im->setResolution(300,300);
    $im->readimage($pdf);
    $im->setImageFormat('jpeg');
    $im->writeImage($jpg);
    $im->clear();
    $im->destroy();
}
Above function which have two primary variables :
- string $pdf – path to file pdf want to convert
- string $jpg – path to file jpg want to created