title: Silent Printing with Ghostscript.NET
body: <p>I'm trying to send a pdf to the printer without the print dialog coming up using GhostScript.NET. My understanding is if I provide the exact name of the printer in the -sOutputFile switch, the user will not be prompted..</p>
  
  <p>The exact name of my printer is 101-XER4250, and in debugging, the name that the processor receives is: "-sOutputFile=%printer%101-XER4250-E".  Is there something that I am missing regarding this? Also if it's worth mentioning, I'm using a Xerox machine with PCL6 drivers. </p>
  
  <p>Here's my example code: </p>
  
  <pre><code>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&lt;string&gt; switches = new List&lt;string&gt;();
                      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);
          }
      }
  </code></pre>