This is a migrated thread and some comments may be shown as answers.

Print silently to default printer

2 Answers 391 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 24 Sep 2014, 04:10 PM
Hi - I'm trying to print silently to the default printer though either the the radPDFViewerNavigator print button or the radPDFViewer default context menu.

For the radPDFViewerNavigator print button click event, I have the following:
me.RadPdfViewer1.Print(False)

This causes the document to print directly to the default printer but then right after that it still brings up the print dialog box.  Is there any way to keep the dialog box from showing?

As for the context menu print option, I can't seem to find a way to get the click event of this in order to override showing the print dialog box.

Any assistance on this will be greatly appreciated.

2 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 24 Sep 2014, 06:00 PM
Sorry - here's some more information:
VS 2010 SP1 .net 4 framework
Telerik pdfViewer v.2014.2.715.40
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Sep 2014, 02:04 PM
Hello David,

Thank you for writing.

The RadPdfViewerNavigator.ShowPrintPreview property controls whether the print preview dialog will be shown when the print button is clicked. However, if it is set to false, the RadPdfViewer's Print(bool showPrinterSettings, RadPrintDocument document) method is used for printing and the printer settings dialog is shown. You can avoid this behavior creating a custom RadPdfViewerElement and overriding its Print(bool showPrinterSettings, RadPrintDocument document) method:
public class CustomPdfViewer : RadPdfViewer
{
    public override string ThemeClassName 
    {
        get
        {
            return typeof(RadPdfViewer).FullName; 
        }
    }
 
    protected override RadPdfViewerElement CreateViewerElement()
    {
        return new CustomPdfViewerElement();
    }
}
 
public class CustomPdfViewerElement : RadPdfViewerElement
{
    protected override Type ThemeEffectiveType    
    {
        get   
        {
            return typeof(RadPdfViewerElement);    
        }
    }
 
    public override void Print(bool showPrinterSettings, RadPrintDocument document)
    {
        if (showPrinterSettings)
        {
            showPrinterSettings = false;
        }
        base.Print(showPrinterSettings, document);
    }
}

As to the context menu, you can change the default behavior of the PdfViewerContextMenu to perform silent printing without displaying the printer setting dialog. For this purpose you should create a derivative of the PdfViewerContextMenu and override the OnPrintItemClicked method:
public Form1()
{
    InitializeComponent();
    this.radPdfViewer1.PdfViewerElement.ContextMenu = new CustomPdfViewerContextMenu(this.radPdfViewer1.PdfViewerElement);
}
 
public class CustomPdfViewerContextMenu : PdfViewerContextMenu
{
    public CustomPdfViewerContextMenu(RadPdfViewerElement pdfViewerElement) : base(pdfViewerElement)
    {
    }
 
    protected override void OnPrintItemClicked(object sender, EventArgs e)
    {
        bool showPrinterSettings = false;
        this.PdfViewerElement.Print(showPrinterSettings);
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
PdfViewer and PdfViewerNavigator
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or