PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] Why isn't it possible for Imagick class to convert pdf files to image files?

 September 18, 2022     image, imagick, pdf, php     No comments   

Issue

I would like to convert a pdf file to images in PHP.

I have got some exception like this:

Fatal error: Uncaught ImagickException: UnableToOpenBlob './sample.pdf': No such file or directory @ error/blob.c/OpenBlob/3533 in D:\Task\Clients\James\toImage\toImage.php:4 Stack trace: #0 D:\Task\Clients\James\toImage\toImage.php(4): Imagick->readImage('./sample.pdf') #1 {main} thrown in D:\Task\Clients\James\toImage\toImage.php on line 4

I wrote some code like as follows.

<?php
    $pdf_url = ('./sample.pdf');
    $imagick = new Imagick();
    $imagick->readImage($pdf_url);
    $imagick->resizeImage( 200, 200, imagick::FILTER_LANCZOS, 0);
    $imagick->setImageFormat( "png" );
    $imagick->writeImage('pdfAsImage.png');

Please help me!


Solution

Here is the code I have ever used before. Use the full path to the image, for example:

$image = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/pdfs/sample.pdf'); 

It should work like a charm!!!



Answered By - CHRIS LEE
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing