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

Not converting to PDF properly

Apr 24, 2014 at 4:39 PM
Using this image: https://www.dropbox.com/s/vfli58sxzmywcy3/22525_008_0030_CC.tif

In the following code, on the last line, the format of the image(magickImageNew ) is .png when it should be .pdf:
        var destinationStream = new FileStream("test.pdf", FileMode.Create);

        //this is the image in dropbox
        string sourceFilePath = @"C:\22525_008_0030_CC.tif";

        MagickImage magickImage1 = new MagickImage(sourceFilePath);

        magickImage1.Strip();
        magickImage1.Format = MagickFormat.Pdf;
        magickImage1.Density = new MagickGeometry(300, 300);

        destinationStream.SetLength(0);
        magickImage1.Write(destinationStream);

        MagickImage magickImageNew;

        destinationStream.Seek(0, SeekOrigin.Begin);
        magickImageNew = new MagickImage(destinationStream);
Let me know if you need more information or if I am missing something.

Thanks, Tim
Coordinator
Apr 24, 2014 at 6:53 PM
You have found a bug in ImageMagick. Thank you for reporting this. I just submitted a patch to the ImageMagick repository. This will be fixed in the next release of Magick.NET.
Apr 24, 2014 at 11:33 PM
You may not know this currently, but any idea if this bug is constrained only to converting to .pdf's, or might it involve more conversion types?
Coordinator
Apr 25, 2014 at 5:05 AM
It is limited to a small set of image types that cannot read directly from a memory blob. It this case it is happening because Magick.NET uses Ghostscript to convert the PDF. The following is happening:
  1. Format of data in stream is checked.
  2. If PDF then write the data of the stream to a temporary file.
  3. Tell Ghostscript to convert the PDF to a PNG file.
  4. Read PNG files and return image.
As you can see the PNG format is used in step 3 and the fix I added will set the format to PDF in step 4.