我正在尝试创建一个简单的C#应用程序,它可以接受StdIn上的输入,并使用Ghostscript处理它来创建PDF,最终我想用输出的PDF做其他事情,但现在只创建PDF就足够了。
我正在考虑用进程运行Ghostscript .exe,但后来我发现了Ghostscript.NET,我正在努力解决的问题是如何将在StdIn上接收到的数据传递给Ghostscript.NET处理器。
using (GhostscriptProcessor ghostscript = new GhostscriptProcessor(gvi))
{
List<string> switches = new List<string>();
switches.Add("-sDEVICE=pdfwrite");
switches.Add("-r300");
switches.Add("-dBATCH");
switches.Add("-dNOPAUSE");
switches.Add("-dSAFER");
switches.Add("-dNOPROMPT");
switches.Add("-sPAPERSIZE=a4");
switches.Add("-sOutputFile = \"" + filename + "\"");
switches.Add("-c");
switches.Add(".setpdfwrite");
switches.Add(@"-f");
switches.Add("-");
ghostscript.Process(switches.ToArray(), new ConsoleStdIO(true, true, true));
}这是来自GitHub存储库的,但我不确定它是否是我需要的:
public class ConsoleStdIO : Ghostscript.NET.GhostscriptStdIO
{
public ConsoleStdIO(bool handleStdIn, bool handleStdOut, bool handleStdErr) : base(handleStdIn, handleStdOut, handleStdErr) { }
public override void StdIn(out string input, int count)
{
char[] userInput = new char[count];
Console.In.ReadBlock(userInput, 0, count);
input = new string(userInput);
}
public override void StdOut(string output)
{
Console.Write(output);
}
public override void StdError(string error)
{
Console.Write(error);
}
}https://stackoverflow.com/questions/44504803
复制相似问题