title: System.Printing namespace set printer page source
body: <p>I am trying to print XPS stream through <code>System.Printing</code> namespace</p>
  
  <pre><code>    Stream stm = pdftron.PDF.Convert.ToXps(pdfdoc);
  
      LocalPrintServer localPrintServer = new LocalPrintServer();
      PrintQueueCollection pqc = localPrintServer.GetPrintQueues();
      PrintQueue defaultPrintQueue = localPrintServer.GetPrintQueue(_PrinterName);
      MemoryStream ms = defaultPrintQueue.GetPrintCapabilitiesAsXml();
  
  
      // Call AddJob
      System.Printing.PrintTicket printTicket = defaultPrintQueue.DefaultPrintTicket;
  
  
      PrintSystemJobInfo myPrintJob = defaultPrintQueue.AddJob();
  
      Stream myStream = myPrintJob.JobStream;//may be this line is wrong, can you suggest alternative?
      myStream = stm;//may be this line is wrong, can you suggest alternative?
      myStream.Close();//may be this line is wrong, can you suggest alternative?
      var inp= defaultPrintQueue.GetPrintCapabilities().InputBinCapability;
      System.Printing.PrintTicket newprintTicket = XpsPrinterUtils.ModifyPrintTicket(printTicket, "psk:JobInputBin", "NS0000:" + _PaperSource);
      System.Printing.ValidationResult vr = defaultPrintQueue.MergeAndValidatePrintTicket(printTicket, newprintTicket);// this line giving exception while changing page source merge and validate
      myPrintJob.Commit();
  </code></pre>
  
  <p><a href="https://github.com/serbrech/wpfprintengine/blob/master/SUT.PrintEngine/Utils/XpsPrinterUtils.cs" rel="nofollow">XpsPrinterUtils.ModifyPrintTicket from github</a></p>
  
  <p>The code is not working and I am stuck with this.</p>
  
  <p>Anyone has good idea or solution to this to print (Xps file stream obtained by pdftron) using system.printing namespace and change page source dynamically.</p>