SELECT * FROM
(SELECT
t.company, SUM(t.dogovor_count_object) AS dogovor_count_object, SUM(t.dogovor_price) AS dogovor_price
FROM (
SELECT
company, SUM(dogovor_count_object) AS dogovor_count_object, ROUND(SUM(dogovor_price), 2) AS dogovor_price
FROM
tab1
GROUP BY company
UNION
SELECT
company, SUM(dogovor_count_object) AS dogovor_count_object, ROUND(SUM(dogovor_price), 2) AS dogovor_price
FROM
tab2
GROUP BY company
......
) AS t
GROUP BY t.company) AS t1
ORDER BY t1.dogovor_price DESC
$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++;
}