Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically "hello world" default SERVER-side printer in ASP.NET MVC
    primarykey
    data
    text
    <p>I have the printer installed and working on an intranet server and I want to programmatically send "hello world" to that default printer. This seems like the simplest thing but I've been googling for a couple hours with no success. (note: I am developing asp.net mvc on the deployment machine itself which is running Windows 7)</p> <p>I tried to translate an example from VB <a href="https://stackoverflow.com/questions/371384/best-way-to-print-from-c-sharp-net">here</a> into C# but it said "no printers are installed".</p> <pre><code>public void TestPrint() { var x = new PrintDocument(); x.PrintPage += new PrintPageEventHandler(PrintPage); x.Print(); } private void PrintPage(Object sender, PrintPageEventArgs e) { var textToPrint = "Hello world"; var printFont = new Font("Courier New", 12); var leftMargin = e.MarginBounds.Left; var topMargin = e.MarginBounds.Top; e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, leftMargin, topMargin); } </code></pre> <p>I had also tried a snippet from MSDN <a href="http://msdn.microsoft.com/en-us/library/ms552912%28v=vs.100%29.aspx#1" rel="nofollow noreferrer">here</a> but it said it did not recognize the printer name.</p> <pre><code>public void TestPrint(string msg) { var server = new LocalPrintServer(); var queue = LocalPrintServer.GetDefaultPrintQueue(); // Call AddJob var job = queue.AddJob(); // Write a Byte buffer to the JobStream and close the stream var stream = job.JobStream; var buffer = UnicodeEncoding.Unicode.GetBytes(msg); stream.Write(buffer, 0, buffer.Length); stream.Close(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload