Articles in this section
Category / Section

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

1 min read

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

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied