Articles in this section
Category / Section

How to silent print the report without using print dialog

3 mins read

The default print option available in the report viewer control shows a print dialog to choose the printer and other settings. The silent printing of report without rendering in preview and without displaying print dialog can be achieved by exporting the reports into PDF and using the PDF document for printing. The Syncfusion ReportWriter library allows to export the report to various file formats without rendering in preview. The following steps illustrates silent printing of a report.

  1. Initialize the ReportWriter and set the ReportPath and ProcessingMode properties that are required to process the report.
  2. Set the DataSources data collection input to the report.
  3. Invoke Save() to store the report stream and load the resultant stream to PdfDocumentView as shown in the following codes

 

C#

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);
PdfDocumentView pdfViewer = new PdfDocumentView();
pdfViewer.Load(stream);
var doc = pdfViewer.PrintDocument as IDocumentPaginatorSource;

 

  1. Get the installed printer list and set the current printer to PrintDialog.
  2. Invoke the PrintDocument() method to print the report without displaying the print dialog options.

 

C#

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:

https://www.syncfusion.com/downloads/support/forum/136369/ze/SilentPrinting-96758534  

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