1

Following gm convert command converts first page of source.pdf to output.tif

convert source.pdf[0] output.tif

I wonder how to do it with Magick.NET library? Following code does not work for me.

using (MagickImage image = new MagickImage("source.pdf"))
{
  image.Write("output.tif");
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
mrd
  • 2,095
  • 6
  • 23
  • 48

2 Answers2

3

ImageMagick cannot handle PostScript and PDF files itself and by its own, for this it uses a third party software called Ghostscript.

So, you need to install the latest version of GhostScript before you can convert a pdf using Magick.NET.

After installing GhostScript use following code to extract first page to TIF-file.

        using (MagickImageCollection image = new MagickImageCollection())
        {
            MagickReadSettings settings = new MagickReadSettings();
            settings.Density = new Density(300, 300); // Settings the density to 300 dpi will create an image with a better quality
            settings.FrameIndex = 0; // First page
            settings.FrameCount = 1; // Number of pages
            image.Read(@"source.pdf", settings);
            image.Write(@"output.tif");
        }

You can adjust quality of resulting TIF by changing settings.Density param (300 dpi is for high quality offset/digital printing, 72 dpi is ok for monitor screens only).

Pavel Dmitrenko
  • 310
  • 2
  • 7
0

I am not a ImageMagick Magick.NET expert, but have you tried simply add [0] to your command as

using (MagickImage image = new MagickImage("source.pdf[0]"))
{
  image.Write("output.tif");
}

ImageMagick does require Ghostscript to be installed to read PDF files As was mentioned previously.

fmw42
  • 46,825
  • 10
  • 62
  • 80