How to display Word Document inside Webview

SwagatikaSwagatika Member ✭✭✭

I have tried Display PDF in Webview . Pdf is Working properly. Now I have to display Word document in Webview .But i am not finding proper solution.Can any one please help me?

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    Try to convert word file to html file, then load local Html content using DependencyService.

    Create an interface.

    public interface IBaseUrl { string Get(); }
    

    Implement the interface on each platform

    [assembly: Dependency (typeof(BaseUrl_Android))]
    namespace WorkingWithWebview.Android
    {
      public class BaseUrl_Android : IBaseUrl
      {
        public string Get()
        {
          return "file:///android_asset/";
        }
      }
    }
    

    Get the file on PCL.

    var source = new HtmlWebViewSource();
    source.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
    

    Tutorial:
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/webview?tabs=windows#local-html-content

Sign In or Register to comment.