Search results
Suggest a FeaturePDF

How to print the report silently without preview the report in Report Viewer

You have to use the Report Writer and PdfDocumentView to print the reports silently without viewing in Report Viewer. Find the following steps to print the report silently: Initialize the Report Writer with reports and data sources, use Save API to get the printable PDF in stream.

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 shown 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");
Having trouble getting help?
Contact Support
Having trouble getting help?
Contact Support