首页 > 解决方案 > Ghostscript PDF 多页多副本打印不整理

问题描述

这是我的 C# 和 Ghostscript.NET 库的无声 PDF 打印代码:

        public bool Print(string inputFile, string printerName, int nrcopies)
        {
            if (nrcopies < 1)
                nrcopies = 1;
            if (!File.Exists(inputFile) || !inputFile.ToLower().EndsWith(".pdf"))
                throw new ApplicationException("File not found or not valid");
            bool defaultPrinter = String.IsNullOrWhiteSpace(printerName);
            using (GhostscriptProcessor processor = new GhostscriptProcessor())
            {
                List<string> switches = new List<string>();
                switches.Add("-empty");
                switches.Add("-dPrinted");
                switches.Add("-dBATCH");
                switches.Add("-dNOPAUSE");
                switches.Add("-dNOSAFER");
                switches.Add("-dNumCopies=" + nrcopies);
                switches.Add("-sDEVICE=mswinpr2");
                if(defaultPrinter)
                    switches.Add("-dQueryUser=3");
                else
                    switches.Add("-sOutputFile=%printer%" + printerName);
                switches.Add("-f");
                switches.Add(inputFile);
                try
                {
                    processor.StartProcessing(switches.ToArray(), null);
                }
                catch (Exception) { }
            }
            return true;
        }

在多份多页打印的情况下,我想拼贴页面。我尝试打印到许多设备,例如,也在 Windows 的 PDF 打印机中,但我总是得到未整理的打印。

这就是我要的:

在此处输入图像描述

但这就是我使用这个参数得到的:

switches.Add("-dNumCopies=" + nrcopies);

在此处输入图像描述

这是等效的 GS 命令:

gswin64.exe -empty -dPrinted -dNOSAFER -dNumCopies=2 -sDEVICE=mswinpr2 -dQueryUser=3 -f "C:\Users\myuser\Desktop\TEST.pdf"

标签: printingghostscriptghostscript.net

解决方案


推荐阅读