1 Replies - 1400 Views - Last Post: 29 March 2013 - 05:18 AM Rate Topic: -----

#1 istore221  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 134
  • Joined: 11-December 11

Print Recipt Via (PrintDialog & PrintDocument )

Posted 29 March 2013 - 03:02 AM

If my Receipt contain huge amount of Items it won't automatically print to the new page it's just stop there

example image with Small Amount of Items

click to see

example image with Huge Amount of Items (This is where the problem occur)

Click here to see

As you can see My Total Amount is gone some of the items gone too (One page is not enough for printing this type of receipt)

My code

 private void button1_Click(object sender, EventArgs e)
        {


            printRecipt();

        }







        void printRecipt()
        {

           

            PrintDialog printDialog = new PrintDialog();

            PrintDocument printDocument = new PrintDocument();

            printDialog.Document = printDocument;

            

            printdocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
            
            printdocument.Print();
            

        }

 void printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {

            

            Graphics graphcs = e.Graphics;
            Bitmap logo = new Bitmap(Coffe_Shop.Properties.Resources.showportfolio_php);


            Font myfont = new Font("Arial", 12);
            SolidBrush Mybrash = new SolidBrush(Color.Gray);
            float fontHeight = myfont.GetHeight();


            int StartX = 350;
            int StratY = 180;
            

            graphcs.DrawImage(logo, 240, 0, StartX, StratY);
            StratY += 30; // 210
            graphcs.DrawString("Welcome to the largest Coffe Shop", myfont, Mybrash, StartX-70, StratY);
            StratY += 40; // 250
            graphcs.DrawString("Invoice No INV1021", myfont, Mybrash, 1, StratY);
            StratY += 30; // 280
            graphcs.DrawString("Time : " + DateTime.Now, myfont, Mybrash, 1, StratY);
            StratY += 20; // 300
            graphcs.DrawString("--------------------------------------------------------------------------------------------------------------------------------------------------------------------", myfont, Mybrash, 1, StratY);

            StratY += 30; // 330

            graphcs.DrawString("Item".PadRight(30), myfont, Mybrash, 30, StratY);
            graphcs.DrawString("Price".PadLeft(30), myfont, Mybrash, 60, StratY);

            StratY += 30; // 360

            
            foreach (DataGridViewRow dr in dataGridView1.Rows)
            {
                string CoffeName = dr.Cells[0].Value.ToString().PadRight(30);
                string UnitPrice = dr.Cells[1].Value.ToString().PadLeft(30);
                string TotalAmount = "LKR " + label1.Text;


                graphcs.DrawString(CoffeName, myfont, Mybrash, 1, StratY);
                graphcs.DrawString(UnitPrice, myfont, Mybrash, 50, StratY);

                StratY += 40;
               
            }

            StratY += 20; // Unknown 

            graphcs.DrawString("Total Amount : LKR 500", myfont, Mybrash, 1, StratY);

           

           
        }











i want to my document to auto grow according to items in receipt thank you !!!

This post has been edited by istore221: 29 March 2013 - 03:07 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Print Recipt Via (PrintDialog & PrintDocument )

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3177
  • View blog
  • Posts: 9,632
  • Joined: 05-May 12

Re: Print Recipt Via (PrintDialog & PrintDocument )

Posted 29 March 2013 - 05:18 AM

You'll have to detect when you've gone past the bottom of the page and print to a new page. If you took time to look at the MSDN documentation you would have seen an example of how this can be done:

http://msdn.microsof....printpage.aspx

I don't quite know what you mean by "auto grow". As far as I know a printer can't make a piece of paper bigger. Additionally, your document is already bigger than the page so why would you want it to grow some more?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1