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

Jump to a page

6 Answers 139 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Sehe
Top achievements
Rank 1
Sehe asked on 26 Sep 2012, 04:50 PM
Hello,

I'm trying to use the PDF viewer to look at a specific page number in a pdf document. I try to set the document source, and then set the CurrentPageNumber property. The viewer will still only load the pdf on the first page. Is there a different way to jump to a specific page in the document?

I used the following:
PdfDocumentSource newDoc = new PdfDocumentSource(new Uri(@"C:\12345.pdf"));
pdfViewer.DocumentSource = newDoc;
pdfViewer.CurrentPageNumber = 5;

6 Answers, 1 is accepted

Sort by
0
Accepted
Kammen
Telerik team
answered on 27 Sep 2012, 08:28 AM
Hi Scott,

The problem is that when you set the CurrentPageNumber, the document has not been loaded yet as the document is loaded asynchronously. Therefore, this code is ignored.

I can suggest you set this property on DocumentChanged event of the RadPdfViewer or the Loaded event of the PdfDocumentSource. Then this code should work as expected.

Greetings,
Kammen
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
Sehe
Top achievements
Rank 1
answered on 27 Sep 2012, 01:22 PM
Hi Kammen,

That worked great. Thank you for the quick response.
0
Flemming
Top achievements
Rank 1
Veteran
answered on 20 Sep 2018, 06:27 PM

I am a little annoyed of this control even though it has a lot of good functionality. I have tried to use it in our grand application and had some issues going to a specific page after the document has loaded and I have created a sample project for you. A little issue there was that I couldn't see the control before I selected a telerik theme. Very frustrating!

I have tried a million different ways of loading the document and waiting for it to load, using timers, the events and other weird work arounds. Nothing worked until I tried the demo project with the code Kammen suggested, which I also tested in the other application, without luck.

It turns out, the problem is because I had the control inside another control, in my case a radtabcontrol. It works as long it's in the first tabitem, or in other words, the tab in focus, when it's loaded.

If I put it in another tab when it loads, then the page command is ignored event though the event is triggered. It doesn't

matter whether I use "GotoPage(10)" or "CurrentPageNumber = 10"

I would have attached the sample project if I could, but only pics are allowed. I will send it in a support ticket instead.

0
Peshito
Telerik team
answered on 21 Sep 2018, 07:25 AM
Hi Flemming,

The PdfViwer does not load the desired page because the content of the tab items is not set to be preserved by default. First you need to set TabControl's IsContentPreserved to True. Then in order to make the PdfViwer change its page, attach to the SelectionChanged event of the TabControl. When the appropriate tab is selected, assure that the PdfViwer is finally loaded and make your changes there. For instance:
<telerik:RadTabControl IsContentPreserved="True" SelectionChanged="RadTabControl_SelectionChanged">
private void RadTabControl_SelectionChanged(object sender, Telerik.Windows.Controls.RadSelectionChangedEventArgs e)
{
    if ((e.AddedItems[0] as RadTabItem).Header.ToString() == "PDF")
    {
        pdfViewer.Loaded += PdfViewer_Loaded;
    }
}
 
private void PdfViewer_Loaded(object sender, RoutedEventArgs e)
{
    pdfViewer.CurrentPageNumber = 10;
    //pdfViewer.GoToPage(10);
}

Regards,
Peshito
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Flemming
Top achievements
Rank 1
Veteran
answered on 21 Sep 2018, 01:50 PM

Hi Peshito, thx for the quick reply.

Is the only reason for "IsContentPreserved=true" just to make sure that the pdfviewer.Loaded event doesn't run more than once?

It seems that if I already have to wait to set the stuff until I am certain that the tab is in view, then I can just run the code there, it works even though don't set IsContentPreserved to true.

0
Peshito
Telerik team
answered on 25 Sep 2018, 11:02 AM
Hello Flemming,

You are welcome!

The IsContentPreserved is used in cases when the user wants to keep the content state. If this is something you don't need for your application you could skip setting it. You can find more information about keeping the content state in our How to Keep the Content State article.

Regards,
Peshito
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PDFViewer
Asked by
Sehe
Top achievements
Rank 1
Answers by
Kammen
Telerik team
Sehe
Top achievements
Rank 1
Flemming
Top achievements
Rank 1
Veteran
Peshito
Telerik team
Share this question
or