Current Page event

3 posts, 0 answers
  1. Andrea
    Andrea avatar
    52 posts
    Member since:
    Oct 2012

    Posted 09 Jun 2014 Link to this post

    Is there an event to sync with the current page on pdf viewer document?

    Since the navigator is in sync there should be, i guess, such an event, but I can't find it.

    Can you please help?
    Best Regards
    Andrea
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Jun 2014 Link to this post

    Hi Andrea,

    Thank you for writing.

    You can use the ScrollerUpdated method for the purpose:
    radPdfViewer1.PdfViewerElement.Scroller.ScrollerUpdated += Scroller_ScrollerUpdated;
     
    void Scroller_ScrollerUpdated(object sender, EventArgs e)
    {
        this.Text =  this.radPdfViewer1.PdfViewerElement.CurrentPage.PageNo.ToString() + " : " + this.radPdfViewer1.PdfViewerElement.Document.Pages.Count.ToString() ;
    }

    I hope this helps.

    Regards,
    Stefan
    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.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andrea
    Andrea avatar
    52 posts
    Member since:
    Oct 2012

    Posted 10 Jun 2014 in reply to Stefan Link to this post

    Thank you that works, this is the first working prototype, if someone needs:


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    namespace BolleWPF
    {
        public partial class PdfSplit : Telerik.WinControls.UI.RadForm
        {
            Telerik.WinControls.UI.RadPdfViewer radPdfViewer1;
            LogicLayer.PdfSplitterBatch sb = new LogicLayer.PdfSplitterBatch();
     
            private int currentPage;
            private int CurrentPage
            {
                get {
                    return currentPage;
                }
                set {
                    currentPage = value;
                    if (pdfSplitterBatchBindingSource.RaiseListChangedEvents)
                    {
                        pdfSplitterBatchBindingSource.RaiseListChangedEvents = false;
                        pdfSplitterBatchBindingSource.Position = currentPage - 1;
                        pdfSplitterBatchBindingSource.RaiseListChangedEvents = true;
                    }
                }
            }
     
            public PdfSplit()
            {
                InitializeComponent();
                pdfSplitterBatchBindingSource.DataSource = sb;
                pdfSplitterBatchBindingSource.PositionChanged += new EventHandler(pdfSplitterBatchBindingSource_PositionChanged);
                radPdfViewer1 = (Telerik.WinControls.UI.RadPdfViewer) Controls.Find("radPdfViewer1", true)[0];
                radPdfViewer1.PdfViewerElement.Scroller.ScrollerUpdated += new EventHandler(Scroller_ScrollerUpdated);
                CurrentPage = 0;
            }
     
            void pdfSplitterBatchBindingSource_PositionChanged(object sender, EventArgs e)
            {
                if (pdfSplitterBatchBindingSource.RaiseListChangedEvents == false || pdfSplitterBatchBindingSource.Position < 0)
                    return;
     
                currentPage = pdfSplitterBatchBindingSource.Position + 1;
                pdfSplitterBatchBindingSource.RaiseListChangedEvents = false;
                radPdfViewer1.PdfViewerElement.GoToPage(currentPage);
                pdfSplitterBatchBindingSource.RaiseListChangedEvents = true;
            }
     
            void Scroller_ScrollerUpdated(object sender, EventArgs e)
            {
                if (radPdfViewer1.PdfViewerElement != null && radPdfViewer1.PdfViewerElement.CurrentPage != null)
                    CurrentPage = radPdfViewer1.PdfViewerElement.CurrentPage.PageNo;
                else
                    CurrentPage = 0;
            }
     
     
            private void radPdfViewer1_DocumentLoaded(object sender, EventArgs e)
            {
                sb.Clear();
                for (int i = 0; i < radPdfViewer1.Document.Pages.Count; ++i)
                {
                    sb.Add(new LogicLayer.PdfSplitter(i+1));
                }
                Scroller_ScrollerUpdated(null, null);
            }     
        }
    }
Back to Top