FlexViewer how to go to a page number

Posted by: couturethierry on 6 May 2021, 2:47 am EST

  • Posted 6 May 2021, 2:47 am EST

    Hello, I did not find how to programmatically display a specific page number of a pdf in a FlexViewer.
    The issue is that I display a pdf in a FlexViewer which is in a TabItem in a TabControl. If I manually display the page 5 of the pdf by scrolling, and then I switch tabs (the FlexViewer is not visible anymore), and then go back to the FlexViewer tab, the pdf displays the page 1 each time (instead of the page 5 in my example), which is annoying.
    Is there a way to avoid this behavior or to programmatically get the current displayed page number and then programmatically go to this page?
    With PdfViewer there is a GoToPage() method, but I did not found an equivalent for FlexViewer.
    How can this be done with FlexViewer?
    Thank you.
  • Marked as Answer

    Replied 6 May 2021, 4:10 pm EST

    Hi Thierry,

    We apologize for any inconvenience caused to you.

    TabControl loads/unloads the controls on switching tabs which causes FlexViewer to reset to its initial state. However, this is an expected behavior.

    As a workaround you can store the current page number when the TabItem (containing FlexViewer) is unselected and use the stored page number to navigate to the page when the TabItem (containing FlexViewer) is selected again.

    In order to get the current page number you can use FlexViewer.Pane's PageNumber property as follows:
     _currentPage = flexViewer.Pane.PageNumber;

    And for navigating to a page you can use FlexViewer.Pane's SetPageIndex method as follows:
    flexViewer.Pane.SetPageIndex(_currentPage - 1, true);

    I have attached a sample which shows the FlexViewer retaining current page while switching tabs. (see FlexViewerSample.zip)

    Best Regards,
    Kartik

    FlexViewerSample.zip
  • Replied 6 May 2021, 5:19 pm EST

    Hi Kartik,
    Thank you for your answer and example, it helped a lot.
    Problem fixed.
    Thierry
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels