ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit)
https://ghostscript.com
GNU Affero General Public License v3.0
391 stars 152 forks source link

Attached pdf file raises a System.AccessViolationException #109

Closed FriscoFromFrance closed 1 year ago

FriscoFromFrance commented 1 year ago

Hi, The attached pdf file raises a System.AccessViolationException.

Please use the following function, with all the last version, to reproduce the problem. Regards.

Error at rasterizer.GetPage

FF

` protected virtual BitmapImage GenerateImage(int page, int xdpi, string pdf_filename) { byte[] bytes; lock (LockObj) { if (!File.Exists(pdf_filename)) return null; bytes = File.ReadAllBytes(pdf_filename); } string b64StrFile = Convert.ToBase64String(bytes);

        var bytes64 = Convert.FromBase64String(b64StrFile);
        using (MemoryStream inputMs = new MemoryStream(bytes64, 0, bytes64.Length))
        {
            lock (LockObj)
            {
                // gsdll64.dll adress must be explicit
                GhostscriptVersionInfo version = new GhostscriptVersionInfo(
                    new Version(0, 0, 0),
                    NativeGsLib, string.Empty,
                    GhostscriptLicense.GPL);

                GhostscriptRasterizer rasterizer = null;
                System.Drawing.Image img = null;

                using (rasterizer = new GhostscriptRasterizer())
                {
                    rasterizer.Open(inputMs, version, false);
                    PageCount = rasterizer.PageCount;
                    img = rasterizer.GetPage(xdpi, page);
                    rasterizer.Close();

                    //Convert Image to BitmapImage
                    Stream ms = new MemoryStream();
                    img.Save(ms, ImageFormat.Bmp);

                    BitmapImage bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.StreamSource = ms;
                    bitmap.EndInit();

                    return bitmap;
                }
            }
        }
    }`

pdferr.pdf

FriscoFromFrance commented 1 year ago

Resolved with last version of gsdll64.dll