Sending String Directly to printer [duplicate]
Asked Answered
U

2

5

Possible Duplicate:
Send document to printer with C#

I want to to Send a String Value directly to printer. of course it is very better that I can send a datatable to printer. but first of all I want to know how I can send my String Value without any prompting for end user to printer. I have searched for 3 hours in internet but found no response. please help me. Thx :)

Unequaled answered 15/9, 2011 at 17:21 Comment(1)
Ironically this is the first hit on Google when you search for this.Thessa
R
19

you can use PrintDocument under System.Drawing.Printing namespace. Print method will print the string using your default printer

string s = "string to print";

PrintDocument p = new PrintDocument();
p.PrintPage += delegate(object sender1, PrintPageEventArgs e1)
{
    e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));

};
try
{
    p.Print();
}
catch (Exception ex)
{
    throw new Exception("Exception Occured While Printing", ex);
}

Found example from here

Romain answered 15/9, 2011 at 17:28 Comment(0)
R
2

Not sure what you were searching for, but here are two articles I found in 1 minute on MSDN about printing. In a nutshell, a PrintDocument class wraps up the functionality with the PrintPage event being raised for each page being printed.

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.aspx

Rabid answered 15/9, 2011 at 17:32 Comment(1)
I believe OP want to send text directly to text printer. like what we used to do pre-windows on com port printers. a text drawn on graphic is not actually a string sent to printer, it is a picture.Setup

© 2022 - 2024 — McMap. All rights reserved.