C# 在哪里复制 gsdll32.dll 以使 PDF 到图像转换器在我的 WPF 应用程序中工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12006855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to copy gsdll32.dll to make PDF to image converter work in my WPF application?
提问by Rahul Ranjan
My PROJECT gives error..
我的项目给出了错误..
*Unable to find an entry point named 'gsapi_new_instance' in DLL 'gsdll32.dll'.*
*无法在 DLL“gsdll32.dll”中找到名为“gsapi_new_instance”的入口点。*
when trying to convert .pdf to image format using Ghost-script Interpreter dll 'gsdll32.dll'
尝试使用 Ghost-script Interpreter dll 'gsdll32.dll' 将 .pdf 转换为图像格式时
Even if I tried copying this dll to all desired places as told in many forums like in
即使我尝试将这个 dll 复制到所有想要的地方,就像在许多论坛中所说的那样
Win\System32 or in The project's directory..The error remains the same..:(
Win\System32 或在项目的目录中..错误保持不变..:(
I have used The PDFConvert.cs class given by Ghost-script and written the following code on my Convert Button click:
我使用了 Ghost-script 提供的 PDFConvert.cs 类,并在我的转换按钮单击上编写了以下代码:
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
//First We Check whether the Dll is present
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\gsdll32.dll"))
{
MessageBox.Show("The library 'gsdll32.dll' required to run this program is not present! download GhostScript and copy \"gsdll32.dll\" to this program directory");
return;
}
if (string.IsNullOrEmpty(txtSingleFile.Text))
{
MessageBox.Show("Enter the File name");
txtSingleFile.Focus();
return;
}
else if (!File.Exists(txtSingleFile.Text))
{
MessageBox.Show("The File Does not exists");
txtSingleFile.Focus();
}
else
ConvertPdfToImage(txtSingleFile.Text);
}
and My ConvertPdfToImage Method is as like:
和我的 ConvertPdfToImage 方法是这样的:
//The Ghost-Script Class Object Creation:
PdfToImage.PDFConvert converter = new PdfToImage.PDFConvert();
public void ConvertPdfToImage(string filename)
{
//bool converted = false;
System.IO.FileInfo input = new FileInfo(filename);
string outPut = string.Format("{0}\{1}{2}", input.DirectoryName, input.Name, txtExtensionName.Text);
converter.OutputFormat = txtExtensionName.Text;
outPut = outPut.Replace(txtExtensionName.Text, string.Format("{1}{0}", txtExtensionName.Text, DateTime.Now.Ticks));
converter.Convert(input.FullName, outPut);
lblConvertingResult.Content = string.Format("{0}:File Converted..!!", DateTime.Now.ToShortTimeString());
}
i believe This error comes because of the Misplacement of gsdll32.dll library because the same code runs well with the sample demo Provided By the Ghost-Script Interpreter API.. Please Suggest The exact Location where I shuld Keep the dll-gsdll32.dll.!!
我相信这个错误是由于 gsdll32.dll 库的错位造成的,因为相同的代码与 Ghost-Script Interpreter API 提供的示例演示运行良好.. 请建议我应该保留 dll-gsdll32.dll 的确切位置。 !!
采纳答案by zurita
I know this question is a little old, but if someone has this problem, i solve it in this way: downloading and install GhostScriptSharp package from Visual Studio http://www.nuget.org/packages/GhostScriptSharp/
我知道这个问题有点老了,但是如果有人遇到这个问题,我是这样解决的:从 Visual Studio http://www.nuget.org/packages/GhostScriptSharp/下载并安装 GhostScriptSharp 包
回答by Yogesh
Try with complete path of dll instead of only name.
Like if your dll kept at D:\TestApplication\bin\gsdll32.dll then,
尝试使用 dll 的完整路径,而不仅仅是名称。
就像如果你的 dll 保存在 D:\TestApplication\bin\gsdll32.dll 那么,
[DllImport("gsdll32.dll", EntryPoint="gsapi_new_instance")]
Above statement will be
以上声明将
[DllImport("D:\TestApplication\bin\gsdll32.dll", EntryPoint="gsapi_new_instance")]
回答by Mike
I finally figured it out. I downloaded the latest DLL, changed the code to look for the updated dll, and it worked.
我终于弄明白了。我下载了最新的 DLL,更改了代码以查找更新的 DLL,并且它起作用了。

