在我的WPF应用程序中复制gsdll32.dll以使PDF到图像转换器工作的位置?

时间:2012-08-17 13:34:01

标签: c# wpf ghostscript ghostscriptsharp

我的项目给出错误..

  

*无法在DLL“gsdll32.dll”中找到名为“gsapi_new_instance”的入口点。*

尝试使用Ghost脚本解释器dll'gsdll32.dll'将.pdf转换为图像格式时

即使我尝试将此dll复制到所有想要的地方,如在

等许多论坛中所说

Win \ System32或项目目录中..错误保持不变.. :(

我使用过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);
}

和我的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());
}

我相信这个错误是因为gsdll32.dll库的错位,因为相同的代码与Ghost-Script Interpreter API提供的示例演示运行良好。 请建议我所在的确切位置保留dll-gsdll32.dll。!!

3 个答案:

答案 0 :(得分:6)

我知道这个问题有点旧,但如果有人遇到这个问题,我就这样解决了:从Visual Studio下载并安装GhostScriptSharp软件包http://www.nuget.org/packages/GhostScriptSharp/

答案 1 :(得分:0)

尝试使用dll的完整路径而不是仅使用名称 就像你的dll保存在D:\ TestApplication \ bin \ gsdll32.dll然后,

[DllImport("gsdll32.dll", EntryPoint="gsapi_new_instance")] 

以上陈述将是

[DllImport("D:\\TestApplication\\bin\\gsdll32.dll", EntryPoint="gsapi_new_instance")]

答案 2 :(得分:-1)

我终于明白了。我下载了最新的DLL,更改了代码以查找更新的dll,然后它起作用了。

相关问题