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)
{
}
}
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With