Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending String Directly to printer [duplicate]

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 :)

like image 253
Shahrokh Avatar asked Dec 02 '22 01:12

Shahrokh


1 Answers

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

like image 79
Damith Avatar answered Dec 04 '22 22:12

Damith