Capture Print Event

2 posts, 1 answers
  1. Benedikt
    Benedikt avatar
    35 posts
    Member since:
    Feb 2018

    Posted 30 Mar Link to this post

    Hi guys,

     

    I'm trying to capture the print event of a RadPDFViewer to not only print the PDF but also save it to a predifined location everytime it is printed.

    Ithought about the Click event in the toolbar, but I also need to capture it if printed from contextmenu.

     

    I have read something about inherit the print command, but I haven't gotten how to do that.

     

    Greetings,

    Benedikt

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2881 posts

    Posted 30 Mar Link to this post

    Hi Benedikt,

    Yes creating a custom command is suitable for this case. Here is an example that shows how you can implement that: 

    public partial class MainWindow : Window
    {      
        public MainWindow()
        {
            InitializeComponent();
            this.pdfViewer.CommandDescriptors = new CustomCommandDescriptors(this.pdfViewer);
        }
    }
    public class MyPrintPdfDocumentCommand : PrintPdfDocumentCommand
    {
        public MyPrintPdfDocumentCommand(FixedDocumentViewerBase fixedDocumentViewerBase) : base(fixedDocumentViewerBase)
        {
        }
        public override void Execute(object parameter)
        {
            //save or perform other action
            base.Execute(parameter);
        }
    }
    public class CustomCommandDescriptors : DefaultCommandDescriptors
    {
        private readonly CommandDescriptor printCommandDescriptor;
    
        public new CommandDescriptor PrintCommandDescriptor
        {
            get
            {
                return this.printCommandDescriptor;
            }
        }
    
        public CustomCommandDescriptors(FixedDocumentViewerBase fixedDocumentViewerBase)   : base(fixedDocumentViewerBase)
        {
            this.printCommandDescriptor = new CommandDescriptor(new MyPrintPdfDocumentCommand(fixedDocumentViewerBase));
        }
    }
    

    I hope this helps. Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top