Magick.net converting PDF to image "unable to create temporary file '': No such file or directory @ error/pdf.c/ReadPDFImage/476"

I'm trying to use Magick.net in a console application to render images from a PDFs and can't seem to get around this problem.

Upon calling "MagickImageCollection.Read(byte[], settings)" I always get a

"unable to create temporary file '': No such file or directory @ error/pdf.c/ReadPDFImage/476"

exception.

I have tried:

I'm out of ideas of what I could be doing wrong

    using (MagickImageCollection images = new MagickImageCollection())
    {
        // Add all the pages of the pdf file to the collection
        images.Read(file, settings);

        switch (orientation)
        {
            case Orientation.Horizontal:
                using (MagickImage image = (MagickImage)images.AppendHorizontally())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Write(ms);

                        return ms.ToArray();
                    }

                }
            case Orientation.Vertical:
                using (MagickImage image = (MagickImage)images.AppendHorizontally())
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        image.Write(ms);

                        return ms.ToArray();
                    }
                }
        }
    }

Upvotes: 2

Views: 2755

Answers (1)

I finally managed to overcome this problem, I was passing the wrong read settings to MagickImageCollection.Read(byte[], settings).

I was telling Magick to read the PDF with the PNG format instead of writing the result to PNG...

MagickReadSettings settings = new MagickReadSettings();
settings.Format = MagickFormat.Png;

I feel a bit silly but the error message completely through me off.

Upvotes: 1

Related Questions