'image converted from pdf file with Imagick got grey background

I'm trying to convert a pdf file to image with imagick in php. The script works fine but the image created has a grey background like if the background of the pdf file is removed

$srcimg = $_SERVER['DOCUMENT_ROOT'] . '/files/pdf_canevas/doc1.pdf'; 

$targetimg = $_SERVER['DOCUMENT_ROOT'] . '/files/pdf_canevas/doc1.jpeg'; 

$im = new imagick();
$im->setResolution(150, 150);
$im->readImage($srcimg);
$im->setImageFormat('jpeg');
$im->setImageCompression(imagick::COMPRESSION_JPEG); 
$im->setImageCompressionQuality(100);
$im->writeImage($targetimg);

$im->clear();
$im->destroy();

this is an exemple of background i got on the conversion image enter image description here

image output enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source