简体   繁体   English

是什么导致Ghostscript返回-100的错误?

[英]What is causing Ghostscript to return an error of -100?

So, I am using Matthew Ephraim's GhostscriptSharp , which is a simple C# wrapper for the unmanaged Win32 Ghostscript DLL in my ASP.Net MVC project. 所以,我使用的是Matthew Ephraim的GhostscriptSharp ,它是我ASP.Net MVC项目中非托管Win32 Ghostscript DLL的简单C#包装器。 Some background: 一些背景:

What I am attempting to do is have a user upload a PDF, and then convert that document into an image that I can then save off into whatever directory I choose (as well as do some other OOP to tie that new image to my site). 我试图做的是让用户上传PDF,然后将该文档转换为图像,然后我可以保存到我选择的任何目录中(以及做一些其他OOP以将新图像绑定到我的网站) 。

I decided to use Mr. Ephraim's wrapper class (GhostscriptSharp) because it was simple enough to use, and it gives me relatively clean access to the DLL's API. 我决定使用Ephraim先生的包装类(GhostscriptSharp)因为它很简单易用,它让我可以相对干净地访问DLL的API。

To test it, I created a dummy C# console application to make sure I could load the DLL, access it, hand it a PDF file on the local disk and then have it write a JPG to the same local disk. 为了测试它,我创建了一个虚拟的C#控制台应用程序,以确保我可以加载DLL,访问它,将PDF文件交给本地磁盘,然后让它将JPG写入同一本地磁盘。 After a few learning experiences, I had success. 经过一些学习经历,我获得了成功。 I would hand it C:\\INPUT.pdf, it would hand me C:\\OUTPUT.jpg. 我会把它交给C:\\ INPUT.pdf,它会递给我C:\\ OUTPUT.jpg。

However, after integrating the GhostScriptSharp code that I had in the console application into my ASP.NET MVC project to the point of where I was calling the DLL with P/invoke, Ghostscript is returning with the int/error code -100 , which is a fatal error (is called E_Fatal in the GhostScript source code). 但是,在将我在控制台应用程序中使用的GhostScriptSharp代码集成到我的ASP.NET MVC项目到我用P / invoke调用DLL的位置之后,Ghostscript将返回int /错误代码-100 ,这是致命错误(在GhostScript源代码中称为E_Fatal )。 I get the same result with both the file that is uploaded through the HTML form, and if I hand it the exact same hard-coded paths that I used in my working console application. 我通过HTML表单上传的文件得到了相同的结果,如果我把它与我在工作控制台应用程序中使用的完全相同的硬编码路径。

For reference, the lines which the exception is thrown are 93-97 in GhostScriptSharp.cs (which is in the CallApi function): 作为参考,抛出异常的行在GhostScriptSharp.cs中是93-97(在CallApi函数中):

int result = InitAPI(gsInstancePtr, args.Length, args);

if (result < 0) {
  throw new ExternalException("Ghostscript conversion error", result);
}

Obviously the exception is thrown because result is -100 . 显然抛出了异常,因为result-100

When InitAPI is called, the instance ptr is a valid int (though I don't know if the instance of GS is correct or not), args has a length of 20 (is a string[] ) of valid GhostScript options (including the correctly-escaped paths to my input & output files). 当调用InitAPI时,实例ptr是一个有效的int (虽然我不知道GS的实例是否正确),args的长度为20(是一个string[] )的有效GhostScript选项(包括正确转义到我的输入和输出文件的路径)。

Long story short, what am I doing wrong? 长话短说,我做错了什么? The error code -100 seems like a catch-all because there is no documentation that states what could possibly be going wrong here. 错误代码-100似乎是一个全能,因为没有文档说明这里可能出错的地方。

Any help is much appreciated, thank you in advance. 非常感谢任何帮助,谢谢你提前。

The -100 error is a generic "fatal error" in GhostScript. -100错误是GhostScript中的一般“致命错误”。

A few things to check: 要检查的一些事项:

1) Permissions (al operations require file access) 1)权限(al操作需要文件访问)

2) Scope, you want to add the GS bin folder to the PATH variables 2)范围,您要将GS bin文件夹添加到PATH变量

3) Consider not calling GhostScript directly from asp.net, GS can be very CPU intensive, rather process files in a separate service 3)考虑不直接从asp.net调用GhostScript,GS可能非常占用CPU,而是在单独的服务中处理文件

I have also created a wrapper, send me an email (address on profile) and I will send it you. 我还创建了一个包装器,给我发了一封电子邮件(个人资料上的地址),我会发给你。 It allows one to pass in the GS bin folder which helps. 它允许一个人传入GS bin文件夹,这有助于。

Most likely the process running the web application does not have permission to write to the directories that you are using. 很可能运行Web应用程序的进程没有写入您正在使用的目录的权限。 I'd suggest creating some specific directory for the app to use and a local id to use to run the app pool, then give that id enough privileges to read/write the directory you've created. 我建议为要使用的应用程序创建一些特定目录,并使用本地ID来运行应用程序池,然后为该id提供足够的权限来读取/写入您创建的目录。

So, ended up being an ID10T error that was derailing me here in this specific instance. 所以,最终成为一个ID10T错误,在这个具体的例子中让我失望。

In Matthew Ephraim's GhostscriptSharp code, he uses a couple of enums to define the options set forth for Ghostscript, and two in particular were the GhostscriptDevices and GhostscriptPageSizes enums. 在Matthew Ephraim的GhostscriptSharp代码中,他使用了几个枚举来定义为Ghostscript设定的选项,其中两个特别是GhostscriptDevicesGhostscriptPageSizes枚举。 Problem is, the way they're written Resharper (Jetbrains Visual Studio plugin) has default rules for naming Enum members. 问题是,他们编写的方式Resharper(Jetbrains Visual Studio插件)具有命名Enum成员的默认规则。 Not thinking, I fixed all of these definitions to please Resharper not realizing that these are passed directly to Ghostscript, so instead of getting a7 for -sPAPERSIZE GS was getting A7 , and for -sDEVICE it was getting Jpeg instead of jpeg . 没想到,我修复了所有这些定义以取悦Resharper没有意识到这些定义直接传递给Ghostscript,所以没有获得a7 -sPAPERSIZE GS获得A7 ,而-sDEVICE获得Jpeg而不是jpeg

For the time being permissions weren't a problem on my end, but only because I run the Cassini web dev test server in Visual Studio. 目前,权限不是我的问题,只是因为我在Visual Studio中运行Cassini Web开发测试服务器。

Thanks to @MarkRedman and @tvanfosson for their helpful suggestions! 感谢@MarkRedman和@tvanfosson的有用建议!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM