简体   繁体   中英

WPF: Display PDF File using WebBrowser

I have a pdf file Placed in the Resource folder. I want to display the PDF File using WebBrowser control. The Main Problem is to find the relative path of the PDF and convert it to absolute, since the WebBrowser dosnt support relative Path.

so far I have the following code( simplified version ):

string GuidePath = "../Resources/Guide/LogViwer User Manual.pdf";
string fullPath = Path.GetFullPath(GuidePath);
Uri GuideURI = new Uri(fullPath, UriKind.Absolute);
Browser.Navigate(GuideURI);

'Browser' is aninstance of a WebBrowser.

The Exeption I get is:

Connot find ...Path... Make sure the path and Internet address is correct.

在文件属性“复制到输出”中,必须将其设置为“如果更新则复制”,并且必须将代码编辑为:

string GuidePath = @"./Resources/Guide/LogViwer User Manual.pdf";

According to the WebBrowser class's documentation, the Navigate method expects a URI, not a filesystem path. You should be able to sort that out thanks to the Uri class:

Browser.Navigate(new Uri(fullPath));

Although I haven't tested that so no promises.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM