Reputation: 943
I have a C# winforms application that opens a pdf file in a webbrowser control. It opens to whatever page I want just fine however if I want to change page (go to a bookmark) the webbrowser stops working. I found this article which explains "Basically Webbrowser.Navigate(url) ONLY fires if the url changes. If it doesn't change it uses a cached version of the web page." however I am calling navigate with a Uri, not a string url like this:
webBrowser.Navigate(new Uri(url));
My question is simply: how can I navigate to another page in the same pdf file, after I have opened the file in the web browser?
Upvotes: 0
Views: 2096
Reputation: 1174
This code may be useful to you.
public static void GetAllText(WebBrowser webBrowser,int toPageNum)
{
webBrowser.Focus();
for(int i = 0; i < toPageNum; i++)
SendKeys.Send("{PGDN}");
}
Upvotes: 0
Reputation: 943
Of course I figure out the problem 2 mins after posting a question. I'll post my solution in hopes it helps someone else anyway;
So to make this work I used this workaround:
webBrowser.AllowNavigation = true;
webBrowser.Hide();
webBrowser.Navigate("about:blank");
await Task.Delay(1000);
webBrowser.Navigate(new Uri(url));
webBrowser.Show();
Upvotes: 0