0

为了在我的 MVC C# 应用程序中安装 Ghostscript,我遵循了大量的 SO 指南,但我无法识别下面的代码。它一直说“找不到 GhostscriptRasterizer(您是否缺少 using 指令或程序集引用?)”

public ActionResult PDFToImages(string pdfFilePath)
        {
            //...

            using (var rasterizer = new GhostscriptRasterizer())
            {
                //...
            }

            //...
        }

我正在使用 Visual Studio,这是我已经尝试过的:

  • 从https://www.ghostscript.com/download.html获取 .exe 文件并安装它。然后在我的项目中手动将 gsdll32.dll 包含为“内容”(菜单:添加现有项);
  • 在 Visual Studio 上,转到“工具>NuGet 包管理器>管理 NuGet 包以获取解决方案”,然后由 Josip Habjan 安装 Ghostscript.NET。
  • 同样在 NuGet 包管理器上尝试安装 Matthieu 的 Ghostscript dll - 出现错误“无法添加对 'gsdll32' 的引用。请确保该文件是可访问的,并且它是一个有效的程序集或 COM 组件。”
  • 在包管理器控制台上做了“Install-Package Ghostscript -Version 9.2.0”,也得到了上面的错误
4

1 回答 1

1

如果您的目标是直接使用 Ghostscript .NET,则无需从项目中引用原始 Ghostscript DLL(如我所说,直到您愿意这样做)。

我在 Windows 7 和 Windows 10 上测试了 Ghostscript .NET,Visual Studio Community 2017 只需按照以下步骤操作:

  1. 安装适用于 Windows 的 Ghostscript 9.52(32 位)

  2. 使用Nuget 包管理器,将Ghostscript .NET添加到我的解决方案中。

  3. 根据需要包括使用代码行(主命名空间和Rasterizer应该可以工作,我还使用Processor):

    using Ghostscript.NET;
    using Ghostscript.NET.Processor;
    using Ghostscript.NET.Rasterizer;

我已经在一个新的控制台应用程序项目中检查了您提供的using子句(它使用 Rasterizer 类),并且如果我之前执行这些步骤,则不会返回任何错误。

请再次尝试重复上述操作,如果您设法以这种方式使用 Ghostscript,请告诉我。

于 2020-08-07T11:38:02.543 回答