This is my silent PDF print code for C# and Ghostscript.NET library:
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;
}
I want to collage pages in case of multiple-copies multiple-page print. I tried to print to many devices, for example, also in windows's PDF printer and I get always not-collated print.
This is what I want:
But this is what I get using this param:
switches.Add("-dNumCopies=" + nrcopies);
This is the equivalent GS command:
gswin64.exe -empty -dPrinted -dNOSAFER -dNumCopies=2 -sDEVICE=mswinpr2 -dQueryUser=3 -f "C:\Users\myuser\Desktop\TEST.pdf"