Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to directly print rdlc report without showing PrintDialog() in C#?

Tags:

c#

printing

rdlc

I have an application where I have to print a RDLC report without showing the printDialog and using the default specified printer defined in the application. Below is my test implementaion code.

    Microsoft.Reporting.WinForms.ReportViewer reportViewerSales = new    Microsoft.Reporting.WinForms.ReportViewer();
    Microsoft.Reporting.WinForms.ReportDataSource reportDataSourceSales = new Microsoft.Reporting.WinForms.ReportDataSource();

    reportViewerSales.Reset();
        reportViewerSales.LocalReport.ReportPath = @"Sales.rdlc";

        reportDataSourceSales.Name = "SalesTableDataSet";

        int i = 1;
        foreach (Product item in ProductSalesList)
        {
            dataset.CurrentSales.AddCurrentSalesRow(i, item.Name, item.Quantity.ToString(), item.Price.ToString(), item.Price.ToString());
            i++;
        }
        reportDataSourceSales.Value = dataset.CurrentSales;
        reportViewerSales.LocalReport.DataSources.Add(reportDataSourceSales);
        dataset.EndInit();

        reportViewerSales.RefreshReport();
        reportViewerSales.RenderingComplete += new RenderingCompleteEventHandler(PrintSales);

And here is my Rendering Complete Method

public void PrintSales(object sender, RenderingCompleteEventArgs e)
    {
        try
        {

            reportViewerSales.PrintDialog();
            reportViewerSales.Clear();
            reportViewerSales.LocalReport.ReleaseSandboxAppDomain();
        }
        catch (Exception ex)
        {
        }
    }
like image 606
Redone Avatar asked Jul 18 '13 07:07

Redone


People also ask

How can I print Rdlc directly without viewing?

How to print the RDLC report directly without viewing in WinRT ReportViewer? Printing reports directly without viewing is not supported. This can be achieved by exporting the reports into PDF and the resultant stream is used in the PdfDocument for printing. Initialize the ReportWriter and load the report stream.

How do I make my Rdlc report landscape?

Right click on the “Report” area in RDLC report and select Report Properties. 2. Now change the Orientation of the report as Landscape to print the report in “Landscape” mode.

How can I get image from Rdlc report from database?

aspx" with "ScriptManager" from the Ajax Extensions section, "SQLDataSource" from the Data section and "ReportViewer" Control from the Reporting section. Bind the table columns with "SQLDataSource" to access the data. Step 3: Add a report named "Image_Report. rdlc" and bind the dataset into the reports using Table.


2 Answers

I just gave a quick look to a class I created to print directly and I think I took some ideas from this walkthrough: Printing a Local Report without Preview

like image 138
tezzo Avatar answered Sep 20 '22 07:09

tezzo


i have made an extension class to @tezzos answer. which might make it more easier.

use this Gist Here to get the extension class i wrote. include it to your project. don't for get namespace :D

LocalReport report = new LocalReport();
            report.ReportEmbeddedResource = "Your.Reports.Path.rdlc";
            report.DataSources.Add(new ReportDataSource("DataSet1", getYourDatasource()));
            report.PrintToPrinter();

PrintToPrinter Method will be available on LocalReport. Might Help someone

like image 24
shakee93 Avatar answered Sep 18 '22 07:09

shakee93