ImageMagick Converting .tif file to .pdf - Causes MagickCoderErrorException

1.1k Views Asked by At

All,

Env: .net 2.0, x64 build of Magick.NET library

I have the following code where I read the .tif file and want to convert it to .pdf.

using (MagickImage image = new MagickImage())
        {
            image.SetDefine(MagickFormat.Tiff, "ignore-tags", "32934");
            image.Read(sourceFilePath);;

            image.Write(targetFilePath);
        }

image.Read() throws MagickCoderErrorException, and the inner exception is MagickCoderWarningException complaining about:

ImageMagick.vshost.exe: Unknown field with tag 32934 (0x80a6) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/880

You can clearly see in my code that I instructed the library to ignore this tag and still I get this exception. Why? Btw, when I catch the exception, and do nothing and call image.Write(my.pdf) I get a pdf generated but I don't want to be simply ignoring exceptions if I am doing something wrong.

2

There are 2 best solutions below

0
On BEST ANSWER

All,

This issue was fixed by having the author add support for ignoring tags in the Magic.net library, check release Magick.NET 7.0.0.0018.

1
On

It looks like the Error Exception was thrown because the Warning Exception wasn't handled correctly.

Your application should except Warning Exceptions, as this is a common message when working with proprietary, non-compliant, or just odd images.

 try {
   image.Read(sourceFilePath);
 } catch (MagickCoderWarningException err) {
   // Evaluate if this exception will introduce undesired behavior
   // If yes... re-throw 
   throw new Exception('This is undesired', err);
 }
 image.Write(targetFilePath);

Why?

I would highly recommend jumping over to ImageMagick's forums, and discover why this is expected behavior. But don't be put-off, or discourage, if the only response is "That's fine", or "Just ignore that".