首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Ghostscript.NET进行静默打印

使用Ghostscript.NET进行静默打印
EN

Stack Overflow用户
提问于 2017-02-25 03:35:25
回答 2查看 1.5K关注 0票数 0

我正在尝试使用GhostScript.NET将pdf发送到打印机,而没有出现打印对话框。我的理解是,如果我在-sOutputFile开关中提供打印机的确切名称,则不会提示用户。

我的打印机的确切名称是101-XER4250,在调试过程中,处理器收到的名称是:"-sOutputFile=% printer %101-XER4250-E“。关于这一点我是不是遗漏了什么?另外,值得一提的是,我使用的是一台带有PCL6驱动程序的复印机。

下面是我的示例代码:

代码语言:javascript
复制
private static void PrintWithGSNET(byte[] pdfFormBytes, string printer, int copies)
    {
        try
        {
            var fileName = @"c:\temp\" + $"{DateTime.Now:yyyyMMddhhmmssffff} - {Security.CurrentUser}";
            using (var file = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
            {
                file.Write(pdfFormBytes, 0, pdfFormBytes.Length);
                using (GhostscriptProcessor processor = new GhostscriptProcessor(GhostscriptVersionInfo.GetLastInstalledVersion(), true))
                {
                    List<string> switches = new List<string>();
                    switches.Add("-empty");
                    switches.Add("-dPrinted");
                    switches.Add("-dBATCH");
                    switches.Add("-dPDFFitPage");
                    switches.Add("-dNOPAUSE");
                    switches.Add("-dNOSAFER");
                    switches.Add("-dNOPROMPT");
                    switches.Add("-dQUIET");
                    switches.Add("-sDEVICE=mswinpr2");
                    switches.Add("-sOutputFile=%printer%" + printer.Trim());
                    switches.Add("-dNumCopies=1");


                    switches.Add(fileName);
                    processor.StartProcessing(switches.ToArray(), null);
                }
                file.Close();
            }
            File.Delete(fileName);
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException($"Error printing. [Printer: {printer.Trim()}] [Copies: {copies}", ex);
        }
    }
EN

回答 2

Stack Overflow用户

发布于 2018-01-30 01:40:08

如果您希望用户不会注意到正在打印文件,可以添加no cancel命令switches.Add("-dNoCancel");

票数 0
EN

Stack Overflow用户

发布于 2017-06-01 00:09:48

它是网络打印机吗?我必须用服务器名称来限定我的打印机名称。

如果我将打印机设置为"printerName“,则会弹出对话框。当我将其更改为@"\servername\printerName“时,对话框消失,它静默打印。

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

https://stackoverflow.com/questions/42446908

复制
相关文章

相似问题

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