0

I am converting a png image to pdf using ImageMagic library(Nuget package Magick.NET-Q16-AnyCPU)

It converts okay and saves the pdf to the destination without any error.

Below is the code which Converts/resize the image to pdf which is working okay.

 public static string ConvertToPdfAndSave(byte[] fileContent)
    {
        var targetFile = "test.pdf";

        using (MagickImage mImage = new MagickImage(fileContent))
        {

            mImage.Quality = 90;
            mImage.Density = new Density(90);
            mImage.Resize(1200, 0);
            mImage.Write(targetFile);
        }           
        return targetFile;
    }

I have to do this thing with multiple images and then I have to read those pdfs using ImageMagick to merge all of them into single PDF. I have installed GhostScript(Initially I had 32 BIT version, now have both 32 and 62 BIT versions of dll) on my system.

When I try to read any converted pdf using ImageMagick, it throws below exception:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt

Code to read the file:

  using (MagickImage mImage = new MagickImage(targetFile))
        {


        }

Here strange thing that, this code works well if I read any other original files from system. It just dont read converted files. It thows exception in constructor.

I am on 64Bit Windows 10 machine.

Any help would be appreciated.

error_handler
  • 1,191
  • 11
  • 19
  • You really need to post an example file that demonstrates a problem. You haven't said which version of Ghostscript you are using. Nor why you think this is a Ghostscript problem, it looks more like IM to me. – KenS Mar 06 '19 at 15:52
  • Perhaps you do not have permission in the ImageMagick policy.xml file to read PDF. See https://stackoverflow.com/questions/52861946/imagemagick-not-authorized-to-convert-pdf-to-an-image/52863413#52863413 – fmw42 Mar 06 '19 at 17:16

0 Answers0