Click here to Skip to main content
14,549,334 members
Rate this:
Please Sign up or sign in to vote.
See more:

I want to print a list of bill. is printing all the bill that is not the problem. when I am printing the bill, in between two bill a lots of space is vacant and go wastage.there is no space is detail, page footer and report footer then also page is going wastage. I want no fixed size for pages, whatever the bill size is there, the next bill should print after that only. my printer is a DMP(epson-EX 300). and paper are in a roll. no single paper is there.

note: above scenario is just an example. This is not any project or assignment. just for knowledge i am asking it.At the time of practice i tried and face this problem.

Please help me.

my code is

part 1:
for (int i = 0; i < listBox1.Items.Count; i++)
                str = listBox1.Items[i].ToString();
                BillReportPrint br = new BillReportPrint();
                br.textBox1.Text = str;
                br.MdiParent = this.MdiParent;

part 2:
private void textBox1_TextChanged(object sender, EventArgs e)
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|Store.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=true;";
            SqlDataAdapter da3 = new SqlDataAdapter("select * from finalbill where billno='" + textBox1.Text + "' order by slno", con);
            DataSet ds3 = new DataSet();
            da3.Fill(ds3, "finalbill");

            SqlDataAdapter da4 = new SqlDataAdapter("select  vat as vat,amount,vatAmount from finalbill where billno='" + textBox1.Text + "' group by vat,Amount,vatAmount ", con);
            DataSet ds4 = new DataSet();
            da4.Fill(ds4, "finalbill");
            BillPrintReport abc = new BillPrintReport();
            crystalReportViewer1.ReportSource = abc;
            ReportDocument rd = (ReportDocument)crystalReportViewer1.ReportSource;
            rd.PrintToPrinter(1, false, 0, 0);
Rate this:
Please Sign up or sign in to vote.

Solution 2

There is no other option with crystal reports as far as i know.I encountered a similar problem,searched the internet, but did not get what i wanted.I later switched to dos printing.I would advise you to do the same.
[no name] 18-May-11 1:18am
I don't know about DOS printing, can you please help me.

if possible then please give me some code.
Rate this:
Please Sign up or sign in to vote.

Solution 1

The crystal report will push out the page corresponding to the page size set in Printer setup,if you want to reduce wastage of paper,set a smaller sized page to the printer setup,if that is not possible switch to Dos Printing in which you can write the contents of the bill to a text document and send the document to print in a printer.
[no name] 16-May-11 12:19pm
Thanks for the response.
My Current page size B5.
I want the same width.
but a lesser height.
Which one to choose as paper size.
please reply
Rate this:
Please Sign up or sign in to vote.

Solution 3

DOS Printing refers to writing the contents of the print to a text document along with some of the commands that the printer understands,some are given below.For example,
StreamWriter objStream;
objStream = File.CreateText("\\Bill.txt");
objStream.WriteLine(Convert.ToChar(14)+"Heading of Bill in Double Width"+Convert.ToChar(18));
String strCmd = Environment.GetEnvironmentVariable("COMSPEC");
                string strPrinterName = ">prn";              
                Process.Start(strCmd, "/C type \\Bill.txt > " +

The following are some of the commands that are self explanatory:
prnALIGHN_LEFT = Chr(27) & Chr(97) & Chr(0)
prnALIGHN_CENTER = Chr(27) & Chr(97) & Chr(1)
prnALIGHN_RIGHT = Chr(27) & Chr(97) & Chr(2)
prnALIGHN_JUSTIFIED = Chr(27) & Chr(97) & Chr(3)
prnDOUBLE_WIDTH = Chr(14)
prnMODE_GRAPHICS = Chr(27) & "t" & "1"
prnFONT_DRAFT = Chr(18)
prnDOUBLE_STRIKE_MODE = Chr(27) & Chr(71)
prnDOUBLE_STRIKE_MODE_CANCEL = Chr(27) & Chr(72)
prn12CPI = Chr(27) & Chr(77)
prn10CPI = Chr(27) & Chr(80)
prnPAGE_LENGTH = Chr(27) & Chr(67)
prnPAGE_EJECT = Chr(12)
[no name] 20-May-11 6:05am
this is not helpful for me, I can't save my crystalreport in a text file.because there are multiple report(including SubReport). Reports are coming from 3 tables. two of them temporary tables.

if any other Idea is there please help me.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100