This project has moved. For the latest updates, please go here.

How to convert each page of PDF to JPG with high resolution?

May 14, 2013 at 10:53 PM
I would like to convert PDF to images. But when I use:
    using (var list = new MagickImageCollection())
    {
        list.Read(file);

        int id = 0;
        foreach (var image in list)
        {
            image.Density = new MagickGeometry(144, 144);
                   
            image.Write(destFolder + "img" + id + ".jpg");
            ++id;
        }
    }
all images looks bad, because of 72dpi resolution (setting Density after Read command doesn't have the desired effect).

On the other hand when I use
    using (var image = new MagickImage())
    {
        image.Quality = 80;
        image.Density = new MagickGeometry(144, 144);
        image.Read(file);
        image.Write(destFolder + "img.jpg");
    }
first page of PDF looks great. But it seems that with that approach it is impossible to read all pages of PDF (only first).

So, is there any way to convert each page of PDF to JPG with high resolution?
Coordinator
May 15, 2013 at 5:09 AM
At this moment there is not an easy way to do that. The Magik++ API i am using does not provide me with a method to do that. You have to read every frame of the image by specifying the page when reading it. I will try to see if i can find a way to do this. Would you mind sending me the PDF so i can use that for testing? For now you have to use this slow method:
using (var list = new MagickImageCollection())
{
  list.Read(file);
  
  for(int id=0; id< list.Count; id++)
  {
    using (MagickImage image = new MagickImage())
    {
      image.Density = new MagickGeometry(144, 144);
      image.Read(file + "[" + id + "]");
      
      image.Quality = 80;
      image.Write(destFolder + "img" + id + ".jpg");
    }
  }
}
May 15, 2013 at 8:46 AM
Thanks for the response, I'll try it later. Here is link for PDF.
Coordinator
May 16, 2013 at 6:37 PM
In changeset 26272 I added a MagickReadSettings object that you can use to specify the Density before reading a multi frame image. I will publish a new release next week that will include this change. Here is an already an example on how to use it:
using (MagickImageCollection collection = new MagickImageCollection())
{
  MagickReadSettings settings = new MagickReadSettings();
  settings.Density = new MagickGeometry(144, 144);

  collection.Read(file, settings);

  int id = 0;
  foreach (MagickImage image in collection)
  {
    image.Write(destFolder + "img" + id + ".png");
    id++;
  }
}
May 16, 2013 at 7:22 PM
Awesome! You are doing great job, looking forward to get new release.