Document support (rtf, doc, docx) for UWP/Windows 10 Mobile

家住魔仙堡 提交于 2019-12-07 12:12:37

问题


How can I display documents (doc, docx, rtf) in an UWP app? The WebView isn't able to do this.

Other options would be calling an external application with Windows.System.Launcher.LaunchUriAsync (e.g. Word) or using a 3rd party library. The requirement is to have the data in the app, because you don't have control over it, if it's handled to another one. Another option would be to convert it to another format (e.g. PDF) which UWP can handle (not really).

Any ideas?


回答1:


If you would like to display word or pdf files in the UWP app you can use WebView control with Google Docs Viewer - I was using it for the online documents.

This is the code:

XAML:

<WebView x:Name="MyWebView"/>

Code behind:

public WebViewPage()
    {
        this.InitializeComponent();
        loadWebView();
    }

    void loadWebView()
    {
        var googleDocsViewer = "http://drive.google.com/viewerng/viewer?embedded=true&url=";
        var pdf = "http://www.uma.es/precarios/images/pdfs/wd-spectools-word-sample-04.doc";
        MyWebView.Navigate(new Uri(googleDocsViewer + pdf));
    }

I did not test it with local files, but I think that should also work. Please try and let me know.




回答2:


UWP can actually handle RTF files with RichEditBox - for more info about that see here in the official documentation (I don't know about RichTextBlock). For Docx support I can recommend a third-party library by Syncfusion, which you can get for free if you meet certain requirements.



来源:https://stackoverflow.com/questions/36572614/document-support-rtf-doc-docx-for-uwp-windows-10-mobile

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