Page 1 of 1

Issues with very high DPI PDFs

Posted: 2019-04-08T15:32:28-07:00
by nickwest
When trying to open a very high DPI (1200 in this case) PDF PHP uses a full CPU core until timeout regardless of file size or complexity of the PDF. This happens on construct of the imagick object before I can check the PDF dimensions.

To replicate make a 10200x13200 gray square in sketch (or your app of choice) and export to PDF. The file will be small (<10kb) but IMagick can't load it in a reasonable amount of time.

Here's the code I used to test:

Code: Select all

$im = new \imagick('/path/to/file.pdf');
$properties = $im->identifyImage();
I timeout while processing the first line. I'm looking for a work around that would let me get the resolution of the PDF before I try to open it so I can prevent a PHP timeout. The PDFs I'm processing are uploaded by end-users. I restrict file size (3MB in this case), page size (8.5" x 11"), and page count (1). I get the file size from the POST, but page size and count I'm getting with IMagick.

The problem being that a high resolution low file size PDF will simply timeout. Does anyone know of a solution for this?

Re: Issues with very high DPI PDFs

Posted: 2019-04-08T15:44:43-07:00
by fmw42
When you use a large density value, the PDF gets rasterized by Ghostscript to a very large image once loaded. Make sure you have enough RAM or set your ImageMagick environment variables map and memory limits to allow the file to page to disk. See https://imagemagick.org/script/resource ... nvironment

Please always provide your IM version and platform/OS. Also check your version of Ghostscript.