Print silently to default printer

3 posts, 0 answers
  1. David
    David avatar
    4 posts
    Member since:
    Jun 2014

    Posted 24 Sep 2014 Link to this post

    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. David
    David avatar
    4 posts
    Member since:
    Jun 2014

    Posted 24 Sep 2014 in reply to David Link to this post

    Sorry - here's some more information:
    VS 2010 SP1 .net 4 framework
    Telerik pdfViewer v.2014.2.715.40
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 29 Sep 2014 Link to this post

    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.
     
Back to Top