Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8152959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:51:49+00:00 2026-06-06T15:51:49+00:00

I want to convert a downloded pdf file to an image via PHP. For

  • 0

I want to convert a downloded pdf file to an image via PHP. For this purpose, I am using Imagemagick extension for PHP. The problem is that if I download the pdf file via file_get_contents function, I cannot create a Imagemagic object with this downloaded content. Here is the code:

<?php

$url = "pdf webaddress";
$pdfData = file_get_contents($url);

try
    {

        $img = new Imagick($pdfData);
        $img->setResolution(480,640);
        $img->setImageFormat("jpeg");
        $img->writeImage("test.jpeg");  

    }
catch(Exception $e)
{
    echo $e->getMessage();
}
?>

I am getting the following error:

Unable to read the file: %PDF-1.6 %גדֿ׃ 7 0 obj <> endobj 86 0 obj <>/Filter/FlateDecode/ID[]/Index[7 146]/Info 6 0 R/Length 257/Prev 592751/Root 8 0 R/Size 153/Type/XRef/W[1 3 1]>>stream h�bbd`bׁ‘6 ’9DעƒH

Now, if I read in the locally stored pdf file, everything works fine. The code is:

 $image = "output.png";
 $img = new Imagick("path to pdf file");
 $img->setResolution(480,640);
 $img->setImageFormat("jpeg");
 $img->writeImage("test.jpeg"); 

Any suggestions, help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:51:51+00:00Added an answer on June 6, 2026 at 3:51 pm

    From the ImageMagick PHP extension documentation page, the Imagick constructor needs a filename parameters which can either be a local file or a URL. :

    Paths can include wildcards for file names, or can be URLs.

    You should pass the URL directly, without file_get_contents, PHP file streams are pretty powerful.

    An other solution for you would be to store the file locally (see tempnam() and file_put_contents), but if you don’t use it for anything else than converting it to an image it’s pretty useless :

    $pdfUrl = "...";
    $tmpFileName = tempnam(sys_get_temp_dir(), "pdf");
    file_put_contents($tmpFileName, file_get_contents($pdfUrl));
    // Do your ImageMagick job
    unlink($tmpFileName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm working on a task that i want to convert text file into PDF
I want to show icon that associated with file type. Something like this But
I want to convert this linear loop into a concurrent one: for(Item item :
I want to convert a binary file into an array of ascii charcters .
I want to convert a CVS project to Subversion, using cvs2svn. It has a
I am trying to convert a PIL image into an array using NumPy. I
I am working on creating thumbnail image from the first page of pdf file.
I want to convert HTML to PDF on the server to allow a client
i want to convert an utf-8 encoded web page source code downloaded using InternetReadFile
I want to download image from internet :: I refer this and try this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.