Reputation: 4837
on my PC this is works fine, but on some PCs the file qould not open, the WebBrowser displays an error, and the file opens in the default PDF program instead of WebBrowser. My code:
Uri GuideURI = new Uri(String.Format("file:///{0}/../PDFs/" + link + ".pdf", Directory.GetCurrentDirectory()));
PDF_Web_Browser.Navigate(GuideURI);
Upvotes: 1
Views: 2208
Reputation: 71
One way to resolve this issue might be to not rely on the PC's PDF reader software. You can use MuPDF as a library to extract the text from PDF and maybe write the content of it in XML format, then navigate to the file.
If you don't want to go this far, you can show an error message when trying to display a PDF file on a PC that doesn't have the required features to open it in the WebBrowser (source).
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
string url = e.Url.ToString();
if (url.StartsWith("res://ieframe.dll/navcancl.htm") && url.EndsWith("pdf"))
{
e.Cancel = true;
MessageBox.Show("Cannot open PDF!");
}
}
Or you can even make a mix of those. Just in case the WebBroswer can't open the PDF file, you can write a message like "PDF addon not detected" and then display the XML file generated with the help of MuPDF library.
Upvotes: 1
Reputation: 724
Maybe its because WebBrowser uses engine of Interneet Explorer. If that person doesn't have installed extension for that, or have older version of IE, he dont be able to open PDF in WebBrowser.
Upvotes: 1