First, I used default media import functionality of WP to import PDF files then I tried with my own script to create JPG thumbnail of the first page. Here it is
Code: Select all
$uploads = wp_upload_dir();
$imagick = new Imagick();
$imagick->readImage('test.pdf[0]');
$imagick->trimImage(2);
$imagick->setImagePage(0, 0, 0, 0);
$imagick->setImageFormat('jpeg');
file_put_contents($uploads['path'] . '/thumbnail.png', $imagick);
Does anyone have any idea about this?