I have this code to convert pdf to tif, it is faster then ImageMagick library so I have to use it. Every thing work good but when I set the x and y dpi it always get ignored. I tried different versions of NuGet GhostScript and I also tried different versions of ghostscript.exe still same issue
Here is my code:
var xDpi = 300; //set the x DPI
var yDpi = 300; //set the y DPI
using (var rasterizer = new GhostscriptRasterizer()) //create an instance for GhostscriptRasterizer
{
rasterizer.Open(fileName); //opens the PDF file for rasterizing
int PdfPages = rasterizer.PageCount;
for (int pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
{
//set the output image(png's) complete path
string outputPNGPath = Path.Combine(fileNameResultDirectory, "00" + pageNumber.ToString() + ".tif");
//converts the PDF pages to png's
Image pdf2PNG = rasterizer.GetPage(xDpi, yDpi, pageNumber);//it gets ignored here.
//save the png's
pdf2PNG.Save(outputPNGPath, ImageFormat.Tiff);
}
}
Also tried:
rasterizer.CustomSwitches.Add("-r300x300");
Also tried:
private static void Test()
{
var localGhostscriptDll = Path.Combine(Environment.CurrentDirectory, "gsdll64.dll");
var localDllInfo = new GhostscriptVersionInfo(localGhostscriptDll);
int desired_x_dpi = 160;
int desired_y_dpi = 160;
string inputPdfPath = @"d:\d.pdf";
string outputPath = @"d:\Test\test.jpg";
GhostscriptRasterizer _rasterizer = new GhostscriptRasterizer();
_rasterizer.Open(inputPdfPath, localDllInfo, false);
for (int pageNumber = 1; pageNumber <= _rasterizer.PageCount; pageNumber++)
{
string pageFilePath = Path.Combine(outputPath, "Page-" + pageNumber.ToString() + ".png");
Image img = _rasterizer.GetPage(desired_x_dpi, desired_y_dpi, pageNumber);
img.Save(pageFilePath, ImageFormat.Png);
}
_rasterizer.Close();
}
In this case I added gsdll32.dll manually to this environment path ..\bin\debug But I get this error: Ghostscript.NET.GhostscriptException: 'Delegate of an exported function couldn't be created for symbol 'gsapi_revision''
Any idea why the x and y dpi gets ignored and in the properties it is gets set to either 96 or 120 as vertical/horizontal resolution. I appreciate any help.