Configure sp Crystal reports to directly print a report

0

Currently I am developing several reports for the company in which I work, the reports are designed in crystal reports. My big drawback is that to be able to print the reports first I have to export them to pdf and then if I print. My question is: Is it possible to configure an icon in which clicking can make the printing of the report without having to export it to pdf or open the print assistant?

I use the version: 13.0.18

by clicking on the print icon it generates an export assistant, I would like it to be a print assistant

    
asked by Andrex_11 26.04.2018 в 16:20
source

2 answers

0

Crystal reports version free, brings the activeX control inactive by default. Create a form with which you could print directly and achieve something similar to what it required. Made from a method which obtained the report that has been selected, once the process is done, it indicated that it selects the default printer and then it connects to the database.

private void metodoprint(){

            //Response.Redirect("../Visor/ConstruirReporte.aspx?Reporte=CRE9&id=" + TextBoxRecibo.Text);
            string sDatosVisorReportesCrystal = Request.QueryString["DatosVisorReportes"];

            DatosVisorReportesCrystal datosVisorReportesCrystal = Utilidades.UrlDecodeFromString<DatosVisorReportesCrystal>(sDatosVisorReportesCrystal);

            string urlReporte = Server.MapPath(datosVisorReportesCrystal.UrlOrigen);

            reporte.Load(urlReporte);

            NameValueCollection parametros = datosVisorReportesCrystal.Parametros;

            if (parametros != null)
            {
                foreach (string s in parametros.AllKeys)
                {
                    if (!string.IsNullOrWhiteSpace(s))
                    {
                        if (!string.IsNullOrEmpty(parametros[s]))
                            reporte.SetParameterValue(s, parametros[s]);
                        else reporte.SetParameterValue(s, null);
                    }

                }
            }

            CrystalReportViewer1.SelectionFormula = datosVisorReportesCrystal.Filtro;

            CrystalReportViewer1.ReportSource = reporte;

            foreach (TableLogOnInfo tlf in CrystalReportViewer1.LogOnInfo)
            {
                tlf.ConnectionInfo = ConexionCrystal.getLogOnInfo().ConnectionInfo;
            }

            // CORRESPONDE A LA CONFIGURACION DE LA IMPRESARORA PREDETERMINADA

            //  RptParamsWithType = new Dictionary<string, string>();
            string NombreImpresora = "";//Donde guardare el nombre de la impresora por defecto

            //Busco la impresora por defecto
            for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
            {
                PrinterSettings a = new PrinterSettings();
                a.PrinterName = PrinterSettings.InstalledPrinters[i].ToString();
                if (a.IsDefaultPrinter)
                {
                    NombreImpresora = PrinterSettings.InstalledPrinters[i].ToString();

                }
            }

            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
            PrinterSettings impresora = new PrinterSettings();
            impresora.PrinterName = NombreImpresora;
            reporte.SetDatabaseLogon("user", "psw.", "nameserver", "db");
            reporte.PrintToPrinter(1, false, 0, 0);
            }

I hope I can help those who have this same difficulty

    
answered by 07.11.2018 / 15:15
source
0

If you use the PrintToPrinter print method directly from the default printer if you have to show or print the report:

Assuming your report was called Report

private void imprimeCR()
{
Informe CR = new InformeCR();
CR.PrintToPrinter(1, false, 0, 0);
CR.Close();
CR.Dispose();
}

Greetings

    
answered by 26.04.2018 в 17:51