Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey ..
In working On a POS ..
I want to print the bill on Roll paper or any type of printer ..
I am using Crystal report ..
My Question is How do I set a custom Length of paper according to the items / records present in the report at that time .. ?
Please help me ..

C#
SqlDataAdapter da = new SqlDataAdapter("SELECT * from BillMaster where InvoiceNo ='" + inv + "'", cs);
               // SqlDataAdapter da = new SqlDataAdapter("SELECT * from BillMaster where InvoiceNo = INV-78472734", cs);
               // SqlDataAdapter da = new SqlDataAdapter("SELECT * from Sales ", cs);
               DataSet4 dr = new DataSet4();
               da.Fill(dr.View4);
               CrystalReport4 cr = new CrystalReport4();
               cr.SetDataSource(dr);
               crystalReportViewer1.ReportSource = cr;

               PrintDocument pd = new PrintDocument();
               string defaultPrinter = pd.PrinterSettings.PrinterName;

               height += (cr.Rows.Count * 5F);
              // MessageBox.Show("Test: " + height);
               PaperSize pkCustomSize1 = new PaperSize("First custom size", 4, (int)height);

               pd.DefaultPageSettings.PaperSize = pkCustomSize1;
               foreach (PaperSize paperSize in pd.PrinterSettings.PaperSizes)
               {
                   if (paperSize.PaperName == "Envelope Monarch")
                   {
                       //MessageBox.Show("Test: " + rptDocument.PrintOptions.PaperSize);
                       try
                       {
                           cr.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)paperSize.RawKind;

                       }
                       catch (Exception Ex)
                       {
                           MessageBox.Show("Exception: " + Ex);
                           return;
                       }

                       //crystalReportViewer1.Refresh();

                   }
               }

               MessageBox.Show("Test: " + cr.PrintOptions.PaperSize);
               MessageBox.Show("Test: " + pd.DefaultPageSettings.PaperSize);
               // cr.PrintOptions.ApplyPageMargins(pageMargins);
               crystalReportViewer1.RefreshReport();
               crystalReportViewer1.Show();
               // cr.PrintOptions.PrinterName = "Hewlett-Packard LaserJet 4100 Series";

               //  cr.PrintToPrinter(1,false, 0, 0);
               // crystalReportViewer1.Refresh();}


What I have tried:

I read the related posts here .. But still cant understand ..
Posted

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