想象PDF到JPG缺少图层。 需要将文件从PDF 1.6转换为1.4

I'm converting PDF files to jpg. PDFs are pretty complicated and consists of lot of images. When I convert pdf, some layers respectively parts of pages are missing. For example:

Here is screenshot from desktop PDF reader application

http://mariusrak.sk/original.png

And here is same part of result of conversion:

http://mariusrak.sk/result.png

As you can see, background and that thing in grey field are missing.

I've tried merging layers and flattenimages, also ($i = $i->flattenimages()) and result is still the same, some parts of images/layers are missing.

//Edit: So here's the code:

ini_set('max_execution_time', 600);

$f = './f_big.pdf';
$I = new Imagick;
$I->setresolution(144, 144);

$p = 0;
while(true){
        try {
                $I->readimage($f.'[' . $p . ']');
                $attrs = $I->identifyimage();
                $dpi = 1600 / ($attrs['geometry']['height'] / $attrs['resolution']['y']);
                $I->setresolution($dpi, $dpi);
                $I->readimage($f.'[' . $p . ']');
        } catch (Exception $E) {
                break;
        }
        $I->writeimage('./big-'.$p.'.jpg');
        $I->clear();
        ++$p;
}

The issue is happening with large files e.g. 8Mb and 46 pages. But when I use same files but only with first two pagesEverything works just fine.

Files are created with InDesign and missing layers are PSD files inside of InDesign project with many layers.

// Edit:

So I found out the problem is with file themselves. Files that are stored in PDF version 1.5 or higher are encoded/stored different than older version. If I save same file to version PDF 1.4 everything works just fine. So it's not matter of size but of version.

I think, the best solution would be to convert file on server. Can anybody recomnd some library or solution to do that? Can be paid.