Tip Ghostscript.Net starter troubles fixes

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,553
Location
Norway
Programming Experience
10+
I used the GhostScript.Net library in a project that needed to show images of PDF pages and ran into a couple of problems.
With simple code like this I got a cryptic FormatException "Input string was not in a correct format." for some files:
Imports Ghostscript.NET.Rasterizer

Dim raster As New GhostscriptRasterizer
raster.Open(filename)
'...
raster.Close()

After some research I found indication at authors Github that international characters in file path/name was the cause, there are some alternatives but my solution was to open a FileStream to the file and open the GhostscriptRasterizer from this stream instead:
Dim s = IO.File.OpenRead(filename)
raster.Open(s)
'...
s.Close()

Then I encountered a few files with pages that simply rendered incorrectly, they were not readable, here I tried to look at every option/setting (not many) that could change the outcome, and stumbled upon interpolation mode that could be set as custom switch like this, I set this right after creating the GhostscriptRasterizer instance:
raster.CustomSwitches.Add("-dNOINTERPOLATE") 'default: -dDOINTERPOLATE

The GhostScript swithes I found here: How to use Ghostscript
With this fix all PDF files I have tried have rendered corrently. Quality degration by dNOINTERPOLATE is not noticable by me with the files I've used.

Getting page images was easy:
For ix = 1 To raster.PageCount                    
      Dim pageimage = raster.GetPage(120, 120, ix)

Next

Hope these tips helps others that want to use this library also.
 
Top Bottom