title: How to print from MVC3 controller from server
body: <p>Code below is used to print from ASP .NET MVC3 application to Samsung ML-331x Series printer connected to IP address in LAN and shared in server as Samsung ML-331x Series</p>
  
  <p>Nothing is printed. Execution stops at <code>doc.Print()</code> line.
  Every controller call adds new unfinished job:</p>
  
  <p><img src="https://i.stack.imgur.com/NeTSQ.png" alt="Spooler output"></p>
  
  <p>Those jobs are never finished, only <code>iisreset</code> clears them.</p>
  
  <p>Server is Windows 2003 + IIS
  It worked in MVC2  .NET 3.5 application. ForteSSL VPN was installed in server and application was upgraded to
  MVC3 and .NET 4.
  (After that printing was not checked immediately, so I'm not sure is this related to those changes).</p>
  
  <p>User NETWORK SERVICE with all permissions is added to printer users but problem persists.
  Running application in development computer by pressing F5 in visual studio with Web Developer server and calling with controller to print to PDF Creator works OK.</p>
  
  <p>How to print from controller in server ?</p>
  
  <pre><code>    public ActionResult PrintTest()
      {
          var doc = new PrintDocument();
          doc.PrinterSettings.PrinterName = "Samsung ML-331x Series";
          doc.PrintPage += new PrintPageEventHandler(TestProvideContent);
          doc.Print();
          return new ContentResult()
          {
              Content = "Printed"
          };
      }
  
      public void TestProvideContent(object sender, PrintPageEventArgs e)
      {
          e.Graphics.DrawString("Test",
            new Font("Arial", 12),
            Brushes.Black,
            e.MarginBounds.Left,
            e.MarginBounds.Top);
      }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Application runs at full trust Level. 
  Application log in event viewer does not have any entries about this.</p>
  
  <p>Using <a href="https://stackoverflow.com/questions/12229823/programmatically-hello-world-default-server-side-printer-in-asp-net-mvc">Programmatically &quot;hello world&quot; default SERVER-side printer in ASP.NET MVC</a> I tried to use printer name with server name as <code>\\SERVER\Samsung ML-331x Series</code> but problem persists.</p>