I found that Ghostscript is able to convert PDF to Image format.
I tried PDF to Image Converter but not able to understand it clearly.
I have installed gs905w64.exe
but when I tried to add reference
to my web application I am getting this error.
A reference to gsdll32.dll could not be added. No type libraries were found in the component.
In this article, we will look into converting PDF files to PNG using Ghostscript.NET. Step 1: Download the GhostScript (8.64) from here. Install it. Step 2: Fire up a console application and from Nuget Package Console issue We have to convert these files into PNG.
Ghostscript is an interpreter for PostScript and Portable Document Format (PDF) files. It consists of a PostScript interpreter layer, and a graphics library. GhostPDF is an interpreter built on top of Ghostscript that handles PDF files. It relies on extensions to the PostScript language/imaging model.
If you want to convert PDF file into image file in production server or any other server, then you should install the Ghostscript (32/64 bit) for that server otherwise it will show you an error. This is just a sample application and you can change or modify anything as per your requirement.
Acrobat tends to be very forgiving of invalid PDF files. Ghostscript tends to expect files to conform to the standard. For example, even though valid PDF files must begin with %PDF, Acrobat will scan the first 1000 bytes or so for this string, and ignore any preceding garbage.
You Do not need to add any DLL reference to your project. First download the gs910w32.exe application file then install it to your local computer. Get the location of the installed .exe file eg:-
"C:\Program Files (x86)\gs\gs8.64\bin\gswin32.exe"
use it in your C# application as :
private void PdfToJpg(string inputPDFFile, string outputImagesPath)
{
string ghostScriptPath = @"C:\Program Files (x86)\gs\gs8.64\bin\gswin32.exe";
String ars = "-dNOPAUSE -sDEVICE=jpeg -r102.4 -o" + outputImagesPath + "%d.jpg -sPAPERSIZE=a4 " + inputPDFFile;
Process proc = new Process();
proc.StartInfo.FileName = ghostScriptPath;
proc.StartInfo.Arguments = ars;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
}
IF your input PDF file name has any spaces, you need to change the argument to
String ars = "-dNOPAUSE -sDEVICE=jpeg -r102.4 -o" + outputImagesPath + "%d.jpg -sPAPERSIZE=a4 " +"\"" + inputPDFFile + "\"";
you can specify the output image's aspect ratio in the argument with the -r flag. If you use "-r300" the width of the image will be 3000 pixel and height will change accordingly, from the above argument you will get 1024 to 768 size jpg image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With