We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to print the RDLC report directly without viewing in WinRT ReportViewer?

Platform: WinRT |
Control: SfReportViewer |
Published Date: May 6, 2015 |
Last Revised Date: July 15, 2021

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. Set the DataSources to it and then export the report into PDF format by using the ReportWriter’s Save API as given in the following code example.

C#

Stream reportStream = assembly.GetManifestResourceStream("DirectPrinting.Grouping Table.rdlc");
ReportWriter writer = new ReportWriter();
writer.ReportProcessingMode = Syncfusion.ReportWriter.ProcessingMode.Local;
writer.DataSources.Clear();
writer.DataSources.Add(new ReportDataSource { Name = "Customers", Value = Customers.GetData() });
writer.LoadReport(reportStream);
MemoryStream stream = new MemoryStream();
writer.Save(stream, WriterFormat.PDF);

 

Load the exported stream into the PdfDocument by using the PdfDocument.LoadFromStreamAsync API. Render each page of the PDF document as BitmapImage and add them to the UI collection (printPreviewPages) by converting the bitmapimage to Image as shown in following code example.

C#

PdfDocument pdfDoc = await PdfDocument.LoadFromStreamAsync(randomStream);
printPreviewPages.Clear();
for (uint i = 0; i < pdfDoc.PageCount; i++)
{
var bitmap = new BitmapImage();
MemoryStream mStream = new MemoryStream();
var outStream = mStream.AsRandomAccessStream();
await pdfDoc.GetPage(i).RenderToStreamAsync(outStream, new PdfPageRenderOptions());
bitmap.SetSource(outStream);
Image image = new Image();
image.Stretch = Stretch.Fill;
image.Source = bitmap;
printPage = new Page();
printPage.Content = image;
printPreviewPages.Add(printPage);
}

 

Add the visual collections to the PrintDocument for printing them.

C#

// Loop over all the preview pages and add  each page to be printed.
for (int i = 0; i < printPreviewPages.Count; i++)
{
    //All pages should be ready at this point...
    printDocument.AddPage(printPreviewPages[i]);
}
PrintDocument printDoc = (PrintDocument)sender;
// Indicates that all the pages to be printed are provided.
printDoc.AddPagesComplete();

 

The following screenshot displays the final output.

The image illustrates the direct printing of report

Figure 1: Direct Printing of report

Sample Link:

https://www.syncfusion.com/downloads/support/directtrac/125170/ze/DirectPrinting-1924529131.zip

ADD COMMENT
You must log in to leave a comment
Comments
Ryan Nebel
Mar 10, 2016
If you need to add report parameters, make sure to set them after you call; writer.LoadReport(reportStream); Reply

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile