"System.Drawing.PrinterException:No printers are installed"
public void printimage() { string path = Server.MapPath("~/bin/Reciept3.rtf"); reader = new StreamReader(path); //Create a Verdana font with size 10 verdana10Font = new Font("Verdana", 10); //Create a PrintDocument object PrintDocument pd = new PrintDocument(); //Add PrintPage event handler pd.PrintPage += new PrintPageEventHandler(this.PrintTextFileHandler); //Call Print Method pd.Print(); } private void PrintTextFileHandler(object sender, PrintPageEventArgs ppeArgs) { //Get the Graphics object Graphics g = ppeArgs.Graphics; float linesPerPage = 0; float yPos = 0; int count = 0; //Read margins from PrintPageEventArgs float leftMargin = ppeArgs.MarginBounds.Left; float topMargin = ppeArgs.MarginBounds.Top; string line = null; //Calculate the lines per page on the basis of the height of the page and the height of the font linesPerPage = ppeArgs.MarginBounds.Height / verdana10Font.GetHeight(g); //Now read lines one by one, using StreamReader while (count < linesPerPage && ((line = reader.ReadLine()) != null)) { //Calculate the starting position yPos = topMargin + (count * verdana10Font.GetHeight(g)); //Draw text g.DrawString(line, verdana10Font, Brushes.Black, leftMargin, yPos, new StringFormat()); //Move to next line count++; } //If PrintPageEventArgs has more pages to print if (line != null) { ppeArgs.HasMorePages = true; } else { ppeArgs.HasMorePages = false; } } private void releaseObject(object obj) { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); obj = null; } catch (Exception ex) { obj = null; MessageBox.Show("Unable to release the Object " + ex.ToString()); } finally { GC.Collect(); } }
string path = Server.MapPath("~/bin/Reciept3.rtf");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)