Category / Section
How to perform silent printing in PDF viewer for ASP.NET MVC (Classic)
1 min read
How to perform silent printing in PDF viewer for ASP.NET MVC (Classic)?
PDF viewer for ASP.NET MVC (classic) does not support silent printing the PDF document to the default printer. However, we can achieve this by a workaround using PdfViewer.Windows.dll.
Please, refer the below code snippet to print the PDF document silently to the default printer
C#
using (MemoryStream memoryStream = new MemoryStream())
{
file.InputStream.CopyTo(memoryStream);
if (System.IO.Path.GetExtension(file.FileName) == ".pdf")
{
/*load the memory stream in PdfLoadedDocument*/
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(memoryStream);
//load the document in pdf document view
Syncfusion.Windows.Forms.PdfViewer.PdfDocumentView view = new Syncfusion.Windows.Forms.PdfViewer.PdfDocumentView();
view.Load(loadedDocument);
//print the document using print dialog
System.Windows.Forms.PrintDialog dialog = new System.Windows.Forms.PrintDialog();
dialog.Document = view.PrintDocument;
dialog.Document.Print();
}
}
Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfViewerMvc4DemoPrint1494181261
Run the sample, browse the file you need to print and click the print button. The document will be printed in the default printer.