C# webBrowser navigate to another page in pdf

喜欢而已 提交于 2019-12-12 04:44:07

问题


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?


回答1:


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();



回答2:


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}");
}


来源:https://stackoverflow.com/questions/39756834/c-sharp-webbrowser-navigate-to-another-page-in-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!