I'm trying to create an image from a pdf using GhostScript. Here is my code:
GhostscriptWrapper.ConvertToBMP(inputPDFFilePath, outputBMPFilePath);
And here's my GhostscriptWrapper
class:
public class GhostscriptWrapper
{
public static void ConvertToBMP(string inputPath, string outputPath)
{
CallAPI(GetArgs(inputPath, outputPath));
}
private static void CallAPI(string[] args)
{
IntPtr ptr;
CreateAPIInstance(out ptr, IntPtr.Zero);
InitAPI(ptr, args.Length, args);
Cleanup(ptr);
}
private static void Cleanup(IntPtr gsInstancePtr)
{
ExitAPI(gsInstancePtr);
DeleteAPIInstance(gsInstancePtr);
}
[DllImport("gsdll32.dll", EntryPoint="gsapi_new_instance")]
private static extern int CreateAPIInstance(out IntPtr pinstance,
IntPtr caller_handle);
[DllImport("gsdll32.dll", EntryPoint="gsapi_delete_instance")]
private static extern void DeleteAPIInstance(IntPtr instance);
[DllImport("gsdll32.dll", EntryPoint="gsapi_exit")]
private static extern int ExitAPI(IntPtr instance);
[DllImport("gsdll32.dll", EntryPoint="gsapi_init_with_args")]
private static extern int InitAPI(IntPtr instance, int argc,
string[] argv);
private static string[] GetArgs(string inputPath, string outputPath)
{
return new string[] { "-dNOPAUSE", "-dBATCH", "-dSAFER",
"-dTextAlphaBits=4", "-dGraphicsAlphaBits=4", "-sDEVICE=bmp16m",
string.Format("-r{0}x{1}", 0x48, 0x48), "-dEPSCrop",
string.Format("-sOutputFile={0}", outputPath), inputPath };
}
}
My problem is that when I run my code on my page, I get this error:
Unable to load DLL 'gsdll32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
I have the actual dll file, I thought maybe I just need to add a reference to my bin folder, but when I try that, I get this error:
A reference to 'D:\gsdll32.dll' could not be added. No type libraries were found in the component
So I'm kind of stuck - I have the dll, but I have no idea how to reference it. Anyone know what I need to do?
In Package Manager Console type: Install-Package Ghostscript.Net
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