$pathToPdf = $_SERVER['DOCUMENT_ROOT'].'/temp/filename.pdf';
$pathToWhereImageShouldBeStored = $_SERVER['DOCUMENT_ROOT'].'/temp/filename.jpg';
$pdf = new Spatie\PdfToImage\Pdf($pathToPdf);
$pageCount = $pdf->getNumberOfPages();
$i = 1;
$j = 0;
while ($j<=$pageCount){
$pathToWhereImageShouldBeStored = $_SERVER['DOCUMENT_ROOT'].'/temp/filename_'.$i.'.jpg';
$pdf->setPage($i)
->saveImage($pathToWhereImageShouldBeStored);
if ($j!=0){
$i++;
}
$j++;
}