I use imagick to convert pdf to jpg to script I have ... it works fine if I give the direct path to the downloaded pdf without the specified page, but when I add [0] to the end of the file path to indicate that I I just want to read the first page, it gives the following error:
"Fatal error: ImagickException exception with message 'Invalid file name provided' Imagick-> readImage ()"
I also tried using '/path/to/file.pdf[0]' directly in the constructor with no luck, but without a page qualifier, which also works fine.
According to the documentation ... this should work. What am I doing wrong here?
$doc_preview = new Imagick(); $doc_preview->setResolution(180,180); $doc_preview->readImage('/path/to/file.pdf[0]'); $doc_preview->setImageFormat('jpeg'); $doc_preview->writeImage('/path/to/file.jpg'); $doc_preview->clear(); $doc_preview->destroy();
UPDATE: I should have mentioned that I am using HHVM. Not sure if this will affect this case ... but me.
UPDATE2: I opened the problem in the github HHVM repository. I hope they fix this error ... until then, the answer I have outlined correctly below is a decent (albeit hacky) workaround.
source share