Directly Print from PDFViewer

As per SFDATAGrid Control, Data exported to PDF File. 

1. In PDF Viewer, How to Directly print the PDF File without selection of Printer (Directly Print as per printer name set by code)

2. How to get the Direct Print Button Click Event in PDFViewer, so that PDF can directly print as per the printer name set by coding.

Thanks
Deepak

3 Replies

KK Karthik Krishnaraj Syncfusion Team October 17, 2018 11:15 AM UTC

Hi Deepak, 
 
Greetings from Syncfusion, 
 
n PDF Viewer, How to Directly print the PDF File without selection of Printer (Directly Print as per printer name set by code) 
We can directly print PDF document by setting the printer name through code level. Please find the below code snippet to print the document through PdfViewerControl. 
 
PdfViewerControl pdfViewerControl = new PdfViewerControl(); 
pdfViewerControl.Load(@"..\..\Data\Barcode.pdf"); 
pdfViewerControl.PrintDocument.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; 
pdfViewerControl.Print(false); 

We can also set the printer name in code level through PrintDialog class while silent printing the document. Please find the KB link from below.
https://www.syncfusion.com/kb/4625/how-to-silent-print-a-pdf-document-to-a-specified-printer
 
 
How to get the Direct Print Button Click Event in PDFViewer, so that PDF can directly print as per the printer name set by coding. 
We can use the ‘ButtonClicked’ event of PdfViewerControl, to set the printer name while printing the document. The ‘ButtonClicked’ event is triggered when we click the buttons in the PdfViewerControl’s toolbar.  
Please find the below code snippet to trigger the ButtonClicked event. 
 
pdfViewerControl.ButtonClicked += PdfViewerControl_ButtonClicked; 
 
private void PdfViewerControl_ButtonClicked(object sender, ButtonClickedEventArgs e) 
        { 
            if (e.ButtonName == "Print") 
            { 
                e.CancelDefaultAction = true; 
               pdfViewerControl.PrintDocument.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; 
                pdfViewerControl.Print(false); 
            } 
        } 
 
 
Regards, 
Karthik. 



NV N V Ramana October 24, 2024 02:21 AM UTC

Is there a way to know if the Print is success or fail or user cancelled or what exactly happend to log?



RB Rajavignesh BalaSankar Syncfusion Team October 24, 2024 03:50 PM UTC

In WPF PdfViewer, The EndPrint event  is triggered when the last page of the document has been printed. However, it is also triggered if the printing process is canceled or if an exception occurs during the process.

MSDN link:PrintDocument.EndPrint Event (System.Drawing.Printing) | Microsoft Learn



Loader.
Up arrow icon