ghostscript.net rasterizer 'gsapi_init_with_args' is

本文关键字:with args is init net ghostscript gsapi rasterizer | 更新日期: 2023-09-27 18:01:22

当我运行这段代码时:

var stream = File.OpenRead(@"C:'tmp'PdfToTest.PDF");
var latestVersion = GhostscriptVersionInfo.GetLastInstalledVersion();
rasterizer = new GhostscriptRasterizer();
rasterizer.Open(stream, latestVersion, false);

我得到这个错误

An exception of type 'Ghostscript.NET.GhostscriptAPICallException' occurred in Ghostscript.NET.dll but was not handled in user code
Additional information: An error occured when call to 'gsapi_init_with_args' is made: -15

错误在这一行:光栅化程序。Open(stream, latestVersion, false);

谁能告诉我是什么导致了这种情况的发生?

我在本地机器上运行这个。在包管理器控制台中安装Ghostscript。一切似乎都是对的,但就是行不通。

ghostscript.net rasterizer 'gsapi_init_with_args' is

-15是一个'rangecheck'错误。应该有相当多的额外反向通道信息,这些信息可能会提供一些有用的细节。然而,因为你没有直接使用Ghostscript,我不能告诉你它可能会去哪里。

你应该把你用作输入的PDF文件放在公开的地方,至少让我们可以看到它。

理想情况下,您应该从命令行重现Ghostscript本身的问题,但无论如何,您必须提供配置信息(即您使用的设置)。Ghostscript的版本(以及它是32位还是64位)也将是有用的信息。

恐怕没有人能对你给我们的东西做什么。

这是我的工作示例。

所以我调用方法ResizePDF(字符串filePath),并给出文件路径包括扩展名(例如。C:'tmp'file.pdf)作为参数。

该方法返回内存流与调整大小的文件,我可以用它来做任何事情。

有一些工作要做,但是目前为止它是工作的。

internal MemoryStream ResizePDF(string filePath)
{
    string inputFilePath = String.Format(@"{0}", filePath);
    GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
    string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
    MemoryStream memStream = null;
    using (GhostscriptProcessor processor = new GhostscriptProcessor())
    {
        try
        {
            processor.Process(GetGsArgs(inputFile, outputPipeHandle));
            byte[] rawDocumentData = gsPipedOutput.Data;
            memStream = new MemoryStream(rawDocumentData);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            gsPipedOutput.Dispose();
            gsPipedOutput = null;
        }
    }
    return memStream;
}
private string[] GetGsArgs(string inputFilePath, string outputFilePath)
{
        List<string> switches = new List<string>();
        switches.Add("-empty");
        switches.Add("-dQUIET");
        switches.Add("-dSAFER");
        switches.Add("-dBATCH");
        switches.Add("-dNOPAUSE");
        switches.Add("-dNOPROMPT");
        switches.Add("-dPDFSETTINGS=/ebook");
        switches.Add("-sDEVICE=pdfwrite");
        switches.Add("-sPAPERSIZE=a4");
        switches.Add("-sOutputFile=" + outputPipeHandle);
        switches.Add("-f");
        switches.Add(inputFilePath);
        return switches.ToArray();
}

谢谢大家