我正嘗試使用GhostScript從pdf創建圖像。這裏是我的代碼:使用GhostScript將PDF轉換爲圖像 - 我如何引用gsdll32.dll?
GhostscriptWrapper.ConvertToBMP(inputPDFFilePath, outputBMPFilePath);
這是我的GhostscriptWrapper
類:
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 };
}
}
我的問題是,當我在我的網頁上運行我的代碼,我得到這個錯誤:
Unable to load DLL 'gsdll32.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
我有實際的dll文件,我想也許我只需要添加一個引用到我的bin文件夾,但是當我嘗試時,我得到這個錯誤:
A reference to 'D:\gsdll32.dll' could not be added. No type libraries were found in the component
所以我有點卡 - 我有DLL,但我不知道如何引用它。任何人都知道我需要做什麼?
解決方案是什麼? 昨天對我來說這工作得很好。然後我移動了整個網站的目錄,現在什麼也沒有。我可以使用包管理器控制檯,但是當我部署到服務器時,我需要它在那裏工作。 – Mike