Click here to Skip to main content
15,037,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to add image from picturebox in bottom of my receipt here is the code that i am trying but it's now print receipt with picture

What I have tried:

C#
private void printreceipt1()
        {
            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;
            //DialogResult result = printdialog23.ShowDialog();
            //if (result == DialogResult.OK)
            //{
            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 = 30;
            int startp = 6;
            int startoo = 180;
            int startpp = 9;
            int startX = 10;
            int startY = 10;
            int offset = 40;
            int offset1 = 260;
            int offset2 = 280;
            int line = 1;
            int line1 = 5;
            int line2 = 6;
            int line3 = 24;
            int line4 = 124;
            int line5 = 32;
            int line6 = 20;
            int line7 = 3;
            int line8 = 6;
            int line9 = 32;
            int offset3 = 250;
            int offset4 = 260;
            int offset5 = 270;

            graphics.DrawString(txtDisplay.Text, new Font("Courier New", 6), new SolidBrush(Color.Black), line, line1);
            graphics.DrawString(setaluefortext00001name, new Font("Courier New", 15), new SolidBrush(Color.Black), starto, startp);
            graphics.DrawString("*****************************************************************", new Font("Courier New", 6), new SolidBrush(Color.Black), line2, line3);
            graphics.DrawString(label4.Text, new Font("Courier New", 6), new SolidBrush(Color.Black), line8, line9);
            //graphics.DrawString("Receipt#:" + label2.Text, new Font("Courier New", 6), new SolidBrush(Color.Red), line4, line5);
            foreach (tblProductEx product in products1)
            {
                //for (int z = 0; z < dataGridView2.Rows.Count - 1; z++)
                //{
                    string productDescription = product.productName.PadRight(30);

                    string productTotal = "Rs:" + string.Format("{0:}", product.productPrice);
                    string prodcutLine = productDescription + productTotal;

                    graphics.DrawString(prodcutLine, f, new SolidBrush(Color.Black), startX, startY + offset);

                    offset = offset + (int)fontHeight + 5;
                //}
            }
            offset = offset + 20;
            tblTransaction transaction = new tblTransaction();
            transaction.transactionDate = DateTime.Now;
            graphics.DrawString("Total To Pay".PadRight(15) + "Rs " + string.Format("{0:}", total1), f, new SolidBrush(Color.Black), startX, startY + offset3);
            graphics.DrawString("Thank You For Coming,".PadRight(15) + string.Format(""), f, new SolidBrush(Color.Black), startX, startY + offset4);
Here i want to add image in receipt graphics.DrawStri
Posted
Updated 7-Oct-16 11:36am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900