首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ghostscript.NET如何处理StdIn上的输入

Ghostscript.NET如何处理StdIn上的输入
EN

Stack Overflow用户
提问于 2017-06-13 00:54:05
回答 0查看 608关注 0票数 2

我正在尝试创建一个简单的C#应用程序,它可以接受StdIn上的输入,并使用Ghostscript处理它来创建PDF,最终我想用输出的PDF做其他事情,但现在只创建PDF就足够了。

我正在考虑用进程运行Ghostscript .exe,但后来我发现了Ghostscript.NET,我正在努力解决的问题是如何将在StdIn上接收到的数据传递给Ghostscript.NET处理器。

代码语言:javascript
复制
        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存储库的,但我不确定它是否是我需要的:

代码语言:javascript
复制
    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);
        }
    }
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44504803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档