I followed this tutorial :
https://www.c-sharpcorner.com/blogs/convert-pdf-file-into-image-filepngjpgjpeg-using-ghostscript
public void ExtracImagesFromPdf(string fileNameResultDirectory)
{
GhostscriptPngDevice img = new GhostscriptPngDevice(GhostscriptPngDeviceType.Png16m);
img.GraphicsAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
img.TextAlphaBits = GhostscriptImageDeviceAlphaBits.V_4;
img.ResolutionXY = new GhostscriptImageDeviceResolution(200, 200);
img.InputFiles.Add(fileNameResultDirectory);
//img.Pdf.FirstPage = 1;
//img.Pdf.LastPage = 1;
img.PostScript = string.Empty;
img.OutputPath = @"C:\Users\name\Desktop\images\Result";
img.Process();
}I get this error: Ghostscript.NET.GhostscriptAPICallException: 'An error occured when call to 'gsapi_init_with_args' is made: -100'
My PDF has more than page.
Tuhin PaulPosted Mar 16, 2023, 1:21 AM
You can try the following things to fix it:
1) Ensure that you have installed Ghostscript correctly on your system and that the installation path is added to the PATH environment variable. You can check this by opening a command prompt and running the command "gswin64c -version". If Ghostscript is installed correctly, you should see the version number printed in the console.
2) Verify that the Ghostscript settings are set correctly for the input file. Make sure that the input file is specified correctly and that the correct input format is selected. You can try modifying the Ghostscript settings to see if this resolves the issue.
3) Verify that the input file is valid and that it can be processed by Ghostscript. If your input file is corrupt or damaged, you may need to repair or recreate the file before you can process it with Ghostscript.
4) If your PDF file contains more than one page, you may need to specify which pages to process. You can try uncommenting the lines that specify the first and last pages to be processed, as shown in the code you posted.
5) Verify that you are using a compatible version of Ghostscript with the Ghostscript.NET library. Ghostscript.NET has been tested with Ghostscript versions 9.14 to 9.27. If you are using a different version of Ghostscript, you may need to update the Ghostscript.NET library or install a compatible version of Ghostscript.
Tuhin PaulPosted Mar 16, 2023, 1:19 AM
The issue is with the Ghostscript initialization. This error can be caused by a number of different issues, including incorrect Ghostscript installation, incorrect Ghostscript settings, or an issue with the input file itself.
Marvin ReidPosted Mar 15, 2023, 4:05 PM
You can convert the PDF to an image format using RasterCodecs. Here is some code that you can build on:
https://www.leadtools.com/help/sdk/tutorials/dotnet-console-load-and-save-images.html
Kareem SaidPosted Feb 6, 2020, 7:03 PM