Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm printing an invoice from my billing project(C# windows application) the invoice size may vary.

I've set a page size of 6 inches width and 5 inches height..

Even if my invoice is just 2 lines it would take up the whole 5 inches height of paper and roll out..

Can i configure it to just stop rolling paper once the print content is finished, so that i can save paper?

I'm using dot matrix printer and rolling paper..

any ideas?
Posted
Comments
Richard MacCutchan 12-Sep-13 4:31am    
Unlikely, since most printers are designed to eject a full page on completion of the print job.
itsmehaboob 12-Sep-13 4:56am    
so how to stop the print job?
Richard MacCutchan 12-Sep-13 5:43am    
At the end of the printing, don't call the method which does the end page functionality. There is no guarantee that this will work, of course, and you will have to experiment to see if it's possible.
CHill60 12-Sep-13 7:53am    
"I've set a page size of 6 inches width and 5 inches height.." ... can you dynamically calculate the page height before printing from the planned content?
itsmehaboob 21-Oct-13 3:36am    
this is the code:

try
{

DataTable dtCompany = ObjBL.getCompany();
decimal Vl;
Vl = 0;
Font PrintFont;
clsCommon.getPrinter("[Rec]");
Position = 0;
PrintFont = new Font("Calbri", 10, FontStyle.Bold);
Position = 75;
if (dtCompany.Rows.Count > 0)
{
PrintFont = new Font("ARIAL", 10, FontStyle.Bold);
e.Graphics.DrawString("" + dtCompany.Rows[0]["Company_name"].ToString() + "", PrintFont, Brushes.Black, 75, Position);


Position = Position + 20;
PrintFont = new Font("Calbri", 9, FontStyle.Regular);
e.Graphics.DrawString("" + dtCompany.Rows[0]["Address"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
Position = Position + 14;
e.Graphics.DrawString("" + dtCompany.Rows[0]["Telephone"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
Position = Position + 14;
e.Graphics.DrawString("" + dtCompany.Rows[0]["Street"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
Position = Position + 14;
e.Graphics.DrawString("" + dtCompany.Rows[0]["Email"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
Position = Position + 14;
}
PrintFont = new Font("ARIAL", 10, FontStyle.Bold);
e.Graphics.DrawString("Sales Invoice", PrintFont, Brushes.Black, 75, Position);
PrintFont = new Font("Calbri", 9, FontStyle.Bold);
Position = Position + 20;
e.Graphics.DrawString("V No :" + dudSVno.Text + "", PrintFont, Brushes.Black, 40, Position);
Position = Position + 25;
e.Graphics.DrawString("Date: " + dtpDate.Value.ToString("dd-MMM-yyyy") + " Time :" + DateTime.Now.ToString("hh:mm tt") + " ", PrintFont, Brushes.Black, 40, Position);
Position = Position + 25;
PrintFont = new Font("Calbri", 5, FontStyle.Regular);
e.Graphics.DrawString("==========================================================", PrintFont, Brushes.Black, 30, Position);
Position = Position + 10;
PrintFont = new Font("ARIAL", 9, FontStyle.Regular);
e.Graphics.DrawString("Srl", PrintFont, Brushes.Black, 40, Position);

e.Graphics.DrawString("Item", PrintFont, Brushes.Black, 100, Position);
e.Graphics.DrawString("Tax", PrintFont, Brushes.Black, 150, Position);
e.Graphics.DrawString("Price", PrintFont, Brushes.Black, 200, Position);

e.Graphics.DrawString("Qty", PrintFont, Brushes.Black, 100, Position);
e.Graphics.DrawString("Gross", PrintFont, Brushes.Black, 150, Position);
e.Graphics.DrawString("Discount", PrintFont, Brushes.Black, 200, Position);
e.Graphics.DrawString("Grand Total", PrintFont, Brushes.Black, 200, Position);
Position = Position + 15;
PrintFont = new Font("Calbri", 5, FontStyle.Regular);
e.Graphics.DrawString("==========================================================", PrintFont, Brushes.Black, 30, Position);
Position = Position + 10;
string S;
PrintFont = new Font("ARIAL", 8, FontStyle.Regular);
for (int i = 0; i < dgSales.Rows.Count; i++)
{

e.Graphics.DrawString(dgSales.Rows[i].Cells[2].Value.ToString(), PrintFont, Brushes.Black, 40, Position);
S = (string)(AlignPosition(dgSales.Rows[i].Cells[3].Value.ToString()));
S = (string)(GetPosition(S));
Position = Position + 20;
e.Graphics.DrawString

1 solution

this is the code:

C#
try
            {

                DataTable dtCompany = ObjBL.getCompany();
                decimal Vl;
                Vl = 0;
                Font PrintFont;
                clsCommon.getPrinter("[Rec]");
                Position = 0;
                PrintFont = new Font("Calbri", 10, FontStyle.Bold);
                Position = 75;
                if (dtCompany.Rows.Count > 0)
                {
                    PrintFont = new Font("ARIAL", 10, FontStyle.Bold);
                    e.Graphics.DrawString("" + dtCompany.Rows[0]["Company_name"].ToString() + "", PrintFont, Brushes.Black, 75, Position);


                    Position = Position + 20;
                    PrintFont = new Font("Calbri", 9, FontStyle.Regular);
                    e.Graphics.DrawString("" + dtCompany.Rows[0]["Address"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
                    Position = Position + 14;
                    e.Graphics.DrawString("" + dtCompany.Rows[0]["Telephone"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
                    Position = Position + 14;
                    e.Graphics.DrawString("" + dtCompany.Rows[0]["Street"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
                    Position = Position + 14;
                    e.Graphics.DrawString("" + dtCompany.Rows[0]["Email"].ToString() + "", PrintFont, Brushes.Black, 60, Position);
                    Position = Position + 14;
                }
                PrintFont = new Font("ARIAL", 10, FontStyle.Bold);
                e.Graphics.DrawString("Sales Invoice", PrintFont, Brushes.Black, 75, Position);
                PrintFont = new Font("Calbri", 9, FontStyle.Bold);
                Position = Position + 20;
                e.Graphics.DrawString("V No :" + dudSVno.Text + "", PrintFont, Brushes.Black, 40, Position);
                Position = Position + 25;
                e.Graphics.DrawString("Date: " + dtpDate.Value.ToString("dd-MMM-yyyy") + " Time :" + DateTime.Now.ToString("hh:mm tt") + " ", PrintFont, Brushes.Black, 40, Position);
                Position = Position + 25;
                PrintFont = new Font("Calbri", 5, FontStyle.Regular);
                e.Graphics.DrawString("==========================================================", PrintFont, Brushes.Black, 30, Position);
                Position = Position + 10;
                PrintFont = new Font("ARIAL", 9, FontStyle.Regular);
                e.Graphics.DrawString("Srl", PrintFont, Brushes.Black, 40, Position);

                e.Graphics.DrawString("Item", PrintFont, Brushes.Black, 100, Position);
                e.Graphics.DrawString("Tax", PrintFont, Brushes.Black, 150, Position);
                e.Graphics.DrawString("Price", PrintFont, Brushes.Black, 200, Position);

                e.Graphics.DrawString("Qty", PrintFont, Brushes.Black, 100, Position);
                e.Graphics.DrawString("Gross", PrintFont, Brushes.Black, 150, Position);
                e.Graphics.DrawString("Discount", PrintFont, Brushes.Black, 200, Position);
                e.Graphics.DrawString("Grand Total", PrintFont, Brushes.Black, 200, Position);
                Position = Position + 15;
                PrintFont = new Font("Calbri", 5, FontStyle.Regular);
                e.Graphics.DrawString("==========================================================", PrintFont, Brushes.Black, 30, Position);
                Position = Position + 10;
                string S;
                PrintFont = new Font("ARIAL", 8, FontStyle.Regular);
                for (int i = 0; i < dgSales.Rows.Count; i++)
                {

                    e.Graphics.DrawString(dgSales.Rows[i].Cells[2].Value.ToString(), PrintFont, Brushes.Black, 40, Position);
                    S = (string)(AlignPosition(dgSales.Rows[i].Cells[3].Value.ToString()));
                    S = (string)(GetPosition(S));
                    Position = Position + 20;
                    e.Graphics.DrawString
 
Share this answer
 

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