Ghostscript.NET
Ghostscript.NET copied to clipboard
Converting PDF pages to images (new PDF interpreter problem)
Hello, i use GhostScript.Net to convert PDF pages to images. I have the following code to achieve this:
public static List<string> GetPDFPageText(Stream pdfStream, string dataPath)
{
try
{
int dpi = 100;
GhostscriptVersionInfo lastInstalledVersion =
GhostscriptVersionInfo.GetLastInstalledVersion(
GhostscriptLicense.GPL | GhostscriptLicense.AFPL,
GhostscriptLicense.GPL);
List<string> textParagraphs = new List<string>();
using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
{
rasterizer.Open(pdfStream, lastInstalledVersion,false);
for (int i = 1; i <= rasterizer.PageCount; i++)
{
// here is the problem, pageImage returns null
System.Drawing.Image pageImage = rasterizer.GetPage(dpi, i);
// rest of code is unrelated to problem..
}
}
return textParagraphs;
}
catch (Exception ex)
{
throw new Exception("An error occurred.");
}
}
I think the new PDF interpreter may have some problems for now since it is new. Image returns null unless i add the following code:
rasterizer.CustomSwitches.Add("-dNEWPDF=false");
It works using old PDF interpreter. I just wanted to let you know about this problem. Thank you in advance.
Yes, I ran into the same problem (the returned image is always null). The work around also worked for me...