【问题标题】:Converting a pdf to an image with GhostScript - how do I reference gsdll32.dll?使用 GhostScript 将 pdf 转换为图像 - 如何引用 gsdll32.dll?
【发布时间】:2012-08-30 12:39:37
【问题描述】:

我正在尝试使用 GhostScript 从 pdf 创建图像。这是我的代码:

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 };
    }
}

我的问题是当我在我的页面上运行我的代码时,我得到了这个错误:

无法加载 DLL 'gsdll32.dll':指定的模块不能 成立。 (HRESULT 异常:0x8007007E)

我有实际的 dll 文件,我想也许我只需要添加对我的 bin 文件夹的引用,但是当我尝试这样做时,我得到了这个错误:

无法添加对“D:\gsdll32.dll”的引用。无类型 在组件中找到库

所以我有点卡住了 - 我有 dll,但我不知道如何引用它。有人知道我需要做什么吗?

【问题讨论】:

  • 解决方案是什么?这对我来说昨天工作得很好。然后我移动了整个站点的目录,现在什么也没有了。我可以使用包管理器控制台,但是当我部署到服务器时,我需要它在那里工作。
  • @Mike 这是一篇关于如何解决此错误的文章。link。我相信它会解决你的问题。

标签: c# asp.net pdf ghostscript


【解决方案1】:

在包管理器控制台中输入:Install-Package Ghostscript.Net

【讨论】:

    【解决方案2】:

    据我了解,您不能只“添加引用”到 DLL,除非 DLL 可能是为 C# 或 .NET 编写的,而 Ghostscript 不是,它是用 C 编写的。

    您需要使用 Win32 API 调用“LoadLibrary”或任何 C#/.NET 等效项。

    您的第一个错误看起来根本无法找到 DLL,您在启动应用程序时是否在当前目录中获得了 DLL 的副本?

    【讨论】:

      【解决方案3】:

      尝试使用 dll 的完整路径,而不是仅使用名称。就像你的 dll 保持在

      D:\TestApplication\bin\gsdll32.dll

      那么,

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

      上面的语句将是

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

      【讨论】:

        【解决方案4】:
        猜你喜欢
        • 2012-11-20
        • 2023-04-08
        • 2012-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-14
        • 2012-10-01
        • 1970-01-01
        相关资源
        最近更新 更多