Reputation: 317
I'm trying to convert a pdf into a PNG, using the code given in the following example (the first function) : https://ghostscriptnet.codeplex.com/SourceControl/latest#Ghostscript.NET/Ghostscript.NET.Samples/Samples/DeviceUsageSample.cs
However, I get this error on launch : " An error occured when call to 'gsapi_init_with_args' is made: -100"... which doesn't mean a lot.
How comes this basic example doesn't work ? I downloaded the latest Ghostscript.NET.dll here : https://ghostscriptnet.codeplex.com/ and added it to the references of the project. My OS is Windows 7 x32 bits and I run VisualStudio as an administrator.
Here is my code :
private void button6_Click(object sender, EventArgs e)
{
GhostscriptPngDevice devPNG = new GhostscriptPngDevice(GhostscriptPngDeviceType.Png256);
devPNG.GraphicsAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
devPNG.TextAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
devPNG.ResolutionXY = new GhostscriptImageDeviceResolution(96, 96);
devPNG.InputFiles.Add(@"D:\Public\FOS.pdf");
devPNG.OutputPath = @"D:\Public\FOS.png";
devPNG.Process();
}
Upvotes: 0
Views: 893
Reputation: 316
Try to replace any character strange (non alpanumeric and spaces, keep filepath "clean" and in shared/temp folder to grant access to any user/process and should work just fine
Upvotes: 0
Reputation: 317
I tried replacing the path of the input and output by one without any space and it now works ! Here is the code I ended up using :
using Ghostscript.NET.Rasterizer;
private void button6_Click(object sender, EventArgs e)
{
int desired_x_dpi = 96;
int desired_y_dpi = 96;
string inputPdfPath = @"D:\Public\temp\rasterizer\FOS.pdf";
string outputPath = @"D:\Public\temp\rasterizer\output\";
using (var rasterizer = new GhostscriptRasterizer())
{
rasterizer.Open(inputPdfPath);
for (var pageNumber = 1; pageNumber <= rasterizer.PageCount; pageNumber++)
{
var pageFilePath = Path.Combine(outputPath, string.Format("Page-{0}.png", pageNumber));
var img = rasterizer.GetPage(desired_x_dpi, desired_y_dpi, pageNumber);
img.Save(pageFilePath + "ImageFormat.Png");
}
}
}
Upvotes: 2