I am currently using Ghostscript.net to process pdf's into images. For multipage document the first page processes then the next throws the error: "Parameter is not valid." Here is the stack trace:
at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
at Ghostscript.NET.Viewer.GhostscriptViewerImage.Lock()
at Ghostscript.NET.Viewer.GhostscriptViewerDisplayHandler.Page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
at Ghostscript.NET.GhostscriptDisplayDeviceHandler.display_page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
And here is the code:
at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
at Ghostscript.NET.Viewer.GhostscriptViewerImage.Lock()
at Ghostscript.NET.Viewer.GhostscriptViewerDisplayHandler.Page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
at Ghostscript.NET.GhostscriptDisplayDeviceHandler.display_page(IntPtr handle, IntPtr device, Int32 copies, Int32 flush)
And here is the code:
Dim TestGWScriptRast As New Ghostscript.NET.Rasterizer.GhostscriptRasterizer
Dim GSLatestVer As Ghostscript.NET.GhostscriptVersionInfo = Ghostscript.NET.GhostscriptVersionInfo.GetLastInstalledVersion()
Try
Dim OutPutDir As String = My.Computer.FileSystem.SpecialDirectories.Temp
TestGWScriptRast.Open(PDFPath, GSLatestVer, True)
For PageToProc As Integer = 1 To TestGWScriptRast.PageCount
If TestGWScriptRast Is Nothing Then
TestGWScriptRast = New Ghostscript.NET.Rasterizer.GhostscriptRasterizer
End If
Dim TempPngImagePath As String = OutPutDir & "\temppng" & Identifier & PageToProc & ".png"
Dim PDFImage As Image = TestGWScriptRast.GetPage(96, 96, PageToProc)
Dim PDFImageClone As New Bitmap(PDFImage.Width, PDFImage.Height)
Dim PDFGraphics As Graphics = Graphics.FromImage(PDFImageClone)
PDFGraphics.DrawImage(PDFImage, 0, 0)
PDFImage.Dispose()
PDFImageClone.Save(TempPngImagePath, Imaging.ImageFormat.Png)
PDFImageClone.Dispose()
GC.Collect()
Next
Is there a workaround or another possible solution to this issue? Any help is greatly appreciated.