当我运行这段代码时:
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错误在这一行: rasterizer.Open(stream,latestVersion,false);
谁能告诉我是什么导致了这种情况的发生?
我在本地机器上运行这个。已在包管理器控制台上安装Ghostscript。一切似乎都是对的,但简单的做法行不通。
发布于 2015-07-07 15:07:41
-15是一个'rangecheck‘错误。应该有相当多的额外反向通道信息,这些信息可能会提供一些有用的细节。但是,由于您没有直接使用Ghostscript,所以我不能告诉您它可能会去哪里。
你应该将你正在使用的PDF文件作为输入放在公共的地方,这样我们至少可以看到它。
理想情况下,你应该从命令行重现Ghostscript本身的问题,但无论如何你都必须提供配置信息(即你使用了什么设置)。Ghostscript的版本(以及它的32位还是64位)也将是有用的信息。
恐怕任何人都不能用你给我们的东西继续下去。
发布于 2015-07-09 04:43:41
这是我的工作示例。
因此,我调用方法ResizePDF(string filePath)并给出包含扩展名的文件路径(例如,C:\tmp\file.pdf)作为参数。
该方法返回带有调整大小的文件的memoryStream,我可以用它来做任何事情。
有一些工作要做,但到目前为止它是有效的。
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();
}谢谢大家。
https://stackoverflow.com/questions/31258536
复制相似问题