When I use GhostscriptRasterizer.GetPage to get PDF page as image, I got the exception: System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb)
SOMETIMES, ERROR throw on this function:
Ghostscript.NET.ImageMemoryHelper.FlipImageVertically(IntPtr src, IntPtr dest, Int32 height, Int32 stride)
Ghostscript.NET.Viewer.GhostscriptViewerDisplayHandler.Page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
Ghostscript.NET.GhostscriptDisplayDeviceHandler.display_page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
Ghostscript.NET.Interpreter.GhostscriptInterpreter.Run(String str)
Ghostscript.NET.Viewer.GhostscriptViewerPdfFormatHandler.ShowPage(Int32 pageNumber)
Ghostscript.NET.Viewer.GhostscriptViewer.ShowPage(Int32 pageNumber, Boolean refresh)
Ghostscript.NET.Rasterizer.GhostscriptRasterizer.GetPage(Int32 xDpi, Int32 yDpi, Int32 pageNumber)
This exception typically happens when using desiredDpi = 300. However, it is working fine if the desiredDpi = 96. But we really want it to be 300 DPI due to image quality issue.
Code:
using (var source = new MemoryStream(documentFileContent))
{
using (var rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
{
System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb)
SOMETIMES, ERROR throw on this function:
Ghostscript.NET.ImageMemoryHelper.FlipImageVertically(IntPtr src, IntPtr dest, Int32 height, Int32 stride)
Ghostscript.NET.Viewer.GhostscriptViewerDisplayHandler.Page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
Ghostscript.NET.GhostscriptDisplayDeviceHandler.display_page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
Ghostscript.NET.Interpreter.GhostscriptInterpreter.Run(String str)
Ghostscript.NET.Viewer.GhostscriptViewerPdfFormatHandler.ShowPage(Int32 pageNumber)
Ghostscript.NET.Viewer.GhostscriptViewer.ShowPage(Int32 pageNumber, Boolean refresh)
Ghostscript.NET.Rasterizer.GhostscriptRasterizer.GetPage(Int32 xDpi, Int32 yDpi, Int32 pageNumber)
This exception typically happens when using desiredDpi = 300. However, it is working fine if the desiredDpi = 96. But we really want it to be 300 DPI due to image quality issue.
Code:
using (var source = new MemoryStream(documentFileContent))
{
using (var rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
{
rasterizer.Open(source, version, true);
for (var i = 1; i <= rasterizer.PageCount; i++)
{
var img = rasterizer.GetPage(desiredDpi, desiredDpi, i);
I have tried to dispose img ASAP, but I still got the except sometimes (not always)