int m_CurrentPage = 0;//for print private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { if (checkBoxQuantity.Checked == true)//for checkBoxQuantity { //********************************END for logo with header dont touch********************** e.Graphics.DrawString("__________________________________________________________________________________", new Font("Arial", 18, FontStyle.Regular), Brushes.Black, new Point(0, 50)); e.Graphics.DrawString("Print Date:" + DateTime.Now.ToString(), new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(840, 85)); //e.Graphics.DrawString("Current Balance:" + LblTotal.Text, new Font("Arial", 12, FontStyle.Bold), Brushes.Black, new Point(573, 220)); e.Graphics.DrawString("Pages:"+ _pageCount, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(5, 85)); e.Graphics.DrawString("-----------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 18, FontStyle.Regular), Brushes.Black, new Point(0, 93)); e.Graphics.DrawString("Stock Number", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(0, 115)); e.Graphics.DrawString("Product Image", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(125, 115)); e.Graphics.DrawString("Description", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(268, 115)); e.Graphics.DrawString("Date Arrival", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(400, 115)); e.Graphics.DrawString("Cost Price", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(500, 115)); e.Graphics.DrawString("Product Status", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(600, 115)); e.Graphics.DrawString("SRP", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(725, 115)); e.Graphics.DrawString("QTY", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(790, 115)); e.Graphics.DrawString("QTYARR", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(865, 115)); e.Graphics.DrawString("MCR", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(965, 115)); e.Graphics.DrawString("ST", new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(1035, 115)); e.Graphics.DrawString("-----------------------------------------------------------------------------------------------------------------------------------", new Font("Arial", 18, FontStyle.Regular), Brushes.Black, new Point(0, 123)); //*********************************************************BODY START ********************************* int height = 100;//size start data for (int l = numberOfItemsPrintedSoFar; l < dtgREPORT.Rows.Count; l++) { numberOfItemsPerPage = numberOfItemsPerPage + 1; if (numberOfItemsPerPage <= 8) { numberOfItemsPrintedSoFar++; if (numberOfItemsPrintedSoFar <= dtgREPORT.Rows.Count) { height += dtgREPORT.Rows[0].Height; e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[1].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(0, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//stock numbr ////try---------------------------***********************************IMAGE int offsety = 143;//space from top int fontheight = 65;//picture spacing 80 for (int i = m_CurrentPage; i < dtgREPORT.Rows.Count - 1; i++) { if (offsety > e.MarginBounds.Height) { e.HasMorePages = true; offsety = 143; return; } byte[] arr = (byte[])dtgREPORT.Rows[i].Cells[2].Value; var image = byteArrayToImage(arr); e.Graphics.DrawImage(image, 143, offsety, 60, 60);//e.Graphics.DrawImage(image, 143, offsety, 60, 60); offsety += fontheight; m_CurrentPage++; } e.HasMorePages = false; //original e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[3].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(275, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//description e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[4].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(400, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//Date arrival e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[5].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(530, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//cost price e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[6].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(600, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//product status e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[7].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(730, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//srp e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[8].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(800, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//qty e.Graphics.DrawString(dtgREPORT.Rows[l].Cells[9].FormattedValue.ToString(), dtgREPORT.Font = new Font("Arial", 10), Brushes.Black, new RectangleF(885, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//qtyarr e.Graphics.DrawString("[ ]", new Font("Arial", 10), Brushes.Black, new RectangleF(955, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//mer e.Graphics.DrawString("[ ]", new Font("Arial", 10), Brushes.Black, new RectangleF(1020, height, dtgREPORT.Columns[2].Width, dtgREPORT.Rows[0].Height));//stock } } else { numberOfItemsPerPage = 0; e.HasMorePages = true; if(e.HasMorePages == true)//for count pages number { _pageCount++; } return; } } numberOfItemsPerPage = 0; numberOfItemsPrintedSoFar = 0; //*************************************end for body Don't Touch *********************** //*******************************************************************for footer*****************************************(don't touch) // Create font and brush. Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); // Create rectangle for drawing. float x = 0.0F; //float y = 1050.0F; float y = 777.0F; float width = 1000.0F; float heightt = 50.0F; RectangleF drawRect = new RectangleF(x, y, width, heightt); // Draw rectangle to screen. //Pen blackPen = new Pen(Color.Black);//for draw rectangle //e.Graphics.DrawRectangle(blackPen, x, y, width, heightt); // Draw string to screen. String drawString = " ******************* Thank you so much ******************* "; e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect); // e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect); } else {} }