How to directly print a report without viewing the Crystal Reports Viewer

I wrote this code to print a Crystal report .. but I got an error

'missing parameters' ...

ReportDocument rdoc = new ReportDocument(); rdoc .Load (Application.StartupPath +"\\" +@ "REPORTS\SalaryReport.rpt"); rdoc.SetDataSource(ds.Tables[0]); ParameterFields pfs = new ParameterFields(); ParameterField pfv = new ParameterField(); ParameterDiscreteValue pdv1 = new ParameterDiscreteValue(); pfv.Name = "fd"; pdv1.Value = fd; pfv.CurrentValues.Add(pdv1); pfs.Add(pfv); ParameterField pfv1 = new ParameterField(); ParameterDiscreteValue pdv11 = new ParameterDiscreteValue(); pfv1.Name = "td"; pdv11.Value = td; pfv1.CurrentValues.Add(pdv11); pfs.Add(pfv1); ParameterField pfv2 = new ParameterField(); ParameterDiscreteValue pdv12 = new ParameterDiscreteValue(); pfv2.Name = "department"; pdv12.Value = Dept; pfv2.CurrentValues.Add(pdv12); pfs.Add(pfv2); crystalReportViewer1.ParameterFieldInfo = pfs; crystalReportViewer1.ReportSource = rdoc; PrinterSettings getprinterName = new PrinterSettings(); rdoc.PrintOptions.PrinterName = getprinterName.PrinterName; rdoc.PrintToPrinter(1, true, 1, 1); 

So help solve this problem ... how to print directly without going through Crystal Reports Viewer?

+4
source share
8 answers
 reportname report1=new reportname(); report1.PrintOptions.PaperOrientation = PaperOrientation.Portrait; report1.PrintOptions.PaperSize = PaperSize.PaperA4; report1.PrintToPrinter(1, false, 0, 15); 

use these codes with the function (Parameters)

0
source

Printing directly to the printer will not solve your problem. Crystal Report requires parameters to be set correctly, and not for some reason.

0
source
  List<BusLib.Report.ReportParameter> ParaList = new List<BusLib.Report.ReportParameter>(); ParaList.Add(new BusLib.Report.ReportParameter("Para1", Value1)); ParaList.Add(new BusLib.Report.ReportParameter("Para2", Value2)); ParaList.Add(new BusLib.Report.ReportParameter("Para3", Value3)); ParaList.Add(new BusLib.Report.ReportParameter("Para4", Value4)); 

After that..

 public void SetParameters(List<BusLib.Report.ReportParameter> pParams) { if (pParams == null) { return; } try { foreach (BusLib.Report.ReportParameter pPara in pParams) { CReport.SetParameterValue(pPara.ParameterName, pPara.ParameterValue); } } catch (Exception Ex) { Val.Message(Ex.Message.ToString()); } } 

you must try this ... you will definitely get success ...

0
source
 private void PrintReport(string reportPath, string PrinterName) { CrystalDecisions.CrystalReports.Engine.ReportDocument rptDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); rptDoc.Load(reportPath); CrystalDecisions.Shared.PageMargins objPageMargins; objPageMargins = rptDoc.PrintOptions.PageMargins; objPageMargins.bottomMargin = 100; objPageMargins.leftMargin = 100; objPageMargins.rightMargin = 100; objPageMargins.topMargin = 100; rptDoc.PrintOptions.ApplyPageMargins(objPageMargins); //rptDoc.PrintOptions.PrinterName = PrinterName; rptDoc.PrintToPrinter(1, false, 0, 0); } private void PrintToPrinter() { PrintReport(System.Windows.Forms.Application.StartupPath +"\\VCrpfrmprint.rpt","Send To OneNote 2010"); } 

rptDoc.PrintToPrinter method prints the specified report pages on a printer selected using the PrintOptions.PrinterName property.
If no printer is selected, the default printer specified in the report will be used.

We use the PrintToPrinter method as:

 public void PrintToPrinter (int nCopies , boolean collated , int startPage , int endPage ); 

Where:

  • nCopies indicates the number of copies to print. A.
  • collated indicates whether to match pages.
  • startPage indicates the first page to print. A.
  • endPage indicates the last page to print. A.
0
source

So simple

  1. Delete these lines:

     crystalReportViewer1.ReportSource = objRpt; crystalReportViewer1.Refresh(); 
  2. Add this line:

     objRpt.PrintToPrinter(1, false, 0, 0); 
0
source

How to print on the client side without using crystal report controls. This (objRpt.PrintToPrinter (1, false, 0, 0);) helps print on the server side.

0
source
  private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (MessageBox.Show("Do you want to Print/View PO? Please be patient as PO may take few seconds to load.", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { pl.POId = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); DataTable dt = new DataTable(); dt = bl.PurchaseOrderPrint(pl); if (dt.Rows.Count > 0) { Reports.PuchaseOrder rpt = new Reports.PuchaseOrder(); Print f = new Print(); rpt.SetDataSource(dt); f.CRV.ReportSource = rpt; f.Show(); } } else { return; } } 
0
source

Source: https://habr.com/ru/post/1488818/


All Articles