Hello Guys,in my new project am facing a problem in printing receipt it's shows blank spaces not but it's now showing data of datagridview in receipt please help me and tell me please where is the problem in my code
What I have tried:
private void printreceiptCash()
{
PrintDialog printdialog1 = new PrintDialog();
PrintDocument printdocument1 = new PrintDocument();
PaperSize bp = new PaperSize("Custom", 100, 200);
printdialog1.Document = printdocument1;
printdocument1.PrintPage += new PrintPageEventHandler(printdocument1_PrintPage);
printdocument1.DefaultPageSettings.PaperSize = bp;
printdocument1.DefaultPageSettings.PaperSize.Height = 1510;
printdocument1.DefaultPageSettings.PaperSize.Width = 320;
printdocument1.PrinterSettings.PrinterName = setaluefortextprinter;
printdocument1.Print();
}
void printdocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics graphics = e.Graphics;
Font f = new Font("Arial", 8);
float fontHeight = f.GetHeight();
int starto = 0;
int startp = 20;
int startoo = 180;
int startpp = 9;
int startX = 10;
int startY = 10;
int offset = 220;
int offset1 = 260;
int offset2 = 280;
int line = 60;
int line1 = 1;
int line2 = 6;
int line3 = 10;
int line4 = 0;
int line5 = 62;
int line6 = 20;
int line7 = 3;
int line8 = 6;
int line9 = 40;
int linesame = 15;
int linesame1 = 50;
int offset3 = 290;
int offset4 = 300;
int offset5 = 270;
int offset6 = 320;
int offset7 = 350;
int offset8 = 80;
int offset9 = 40;
int offset10 = 320;
graphics.DrawString("ABC Branch", new Font("Courier New", 9), new SolidBrush(Color.Black), line2, line3);
graphics.DrawString("Cold Drinks", new Font("Courier New", 6), new SolidBrush(Color.Black), starto, startp);
graphics.DrawString("All Kinds Of SoftDrinks", new Font("Courier New", 6), new SolidBrush(Color.Black), line8, line9);
graphics.DrawString("Cash Memo", new Font("Courier New", 6), new SolidBrush(Color.Black), linesame, linesame1);
graphics.DrawString("-------------------------------------------------", new Font("Courier New", 6), new SolidBrush(Color.Red), line4, line5);
for (int z = 0; z < dataGridView1.Rows.Count; z++)
{
string productDescription = dataGridView1.Rows[z].Cells[0].Value.ToString();
string flaours = dataGridView1.Rows[z].Cells[3].Value.ToString();
string productTotal1 = " Rs " + dataGridView1.Rows[z].Cells[0].Value.ToString();
string prodcutLine = productDescription + flaours;
graphics.DrawString(prodcutLine, new Font("Courier New", 9), new SolidBrush(Color.Black), startX, startY + offset);
offset = offset + (int)fontHeight + 5;
}
offset = offset + 20;
graphics.DrawString("Total To Pay".PadRight(15) + "Rs " + string.Format("{0:}", textBox2.Text), f, new SolidBrush(Color.Black), startX, startY + offset3);
graphics.DrawString("Thank You For Choosing US,".PadRight(15) + string.Format(""), f, new SolidBrush(Color.Black), startX, startY + offset4);