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

Silently printing SSRS, RDL and RDLC reports programmatically in c# without preview


This section describes how to programmatically print a report without viewing in the report viewer. This can be achieved by exporting a report into a PDF format using the Report Writer and resultant stream, which is used in the PdfDocumentView for printing.

 

You can create a simple Report Writer sample in WPF with the help of below Getting Started documentation. The following code snippet is used to export an RDLC report to a PDF document.

 

string reportPath = @"../../ReportTemplate/Product Details.rdlc";
ReportWriter reportWriter = new ReportWriter(reportPath);
reportWriter.ReportProcessingMode = ProcessingMode.Local;
reportWriter.DataSources.Clear();
reportWriter.DataSources.Add(new ReportDataSource { Name = "DataSet1", Value = ProductCatalog.GetData() });
MemoryStream stream = new MemoryStream();
reportWriter.Save(stream, WriterFormat.PDF);

 

Load the exported stream into the PdfDocumentView using the PdfDocumentView.Load API and add the available printers to a list for printing the report using the Windows PrintDialog as given in the following code example.

 

PdfDocumentView pdfdoc = new PdfDocumentView();
pdfdoc.Load(stream);
var doc = pdfdoc.PrintDocument as IDocumentPaginatorSource;
PrintDialog printDialog = new PrintDialog();
List<string> printersList = new List<string>();
List<string> serversList = new List<string>();
var server = new PrintServer();
var queues = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local });
foreach (var queue in queues)
{
 if (!serversList.Contains(queue.HostingPrintServer.Name))
 {
  serversList.Add(queue.HostingPrintServer.Name);
 }
 printersList.Add(queue.FullName);
}
server = new PrintServer(serversList[0].ToString());
PrintQueue printer1 = server.GetPrintQueue(printersList[2].ToString());
printDialog.PrintQueue = printer1;
printDialog.PrintDocument(doc.DocumentPaginator, "PDF PRINTER");

 

 

Sample

Download silent printing sample

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Soumya
Feb 08, 2019

how to set default printer name here

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