Xamarin Forms UWP - Display PDF

妖精的绣舞 提交于 2019-12-18 18:02:11

问题


Please, help me and tell me what am I missing.

My goal is to display simple PDF file (stored locally for example) in the WebView control. Can I bind path of the file to the Source property of the WebView? Or what is the correct way to show PDF in UWP?

P.S. and if the only option is to do like here - how must I add pdf.js to my project??


回答1:


My goal is to display simple PDF file (stored locally for example) in the WebView control.

If you want to display pdf in WebView control, then the methods in Display a Local PDF File in a WebView is most like the only way to solve your problem.

You can follow the steps in the xamarin official document, and here are some additional tips we need to pay attention to:

  1. After downloading pdfjs, for UWP app, you need to copy the entire folder into the Assets folder, make sure that the folder is named "pdfjs", otherwise you will need to modify the code to change the path.

  2. Your .pdf file should be stored into the Content folder under the Assets folder, it means you will need to create a new folder named "Content" under Assets and copy your .pdf file into this folder. Otherwise, you will also need to modify the code to change the path.

  3. After copying your .pdf file into the "Content" folder, don't forget to change the Build Action of this file to Content like this:

Or what is the correct way to show PDF in UWP?

In uwp app, you can use Image to show PDF file, you can refer to the official PDF document sample. But I don't know if PDF can be displayed as Image in Android and IOS apps, since you're developing a cross-platform project, I think it's better to use the built-in method to solve such problem.

If a demo for xamarin UWP is needed, you can leave a comment, I will upload my demo later.



来源:https://stackoverflow.com/questions/39379475/xamarin-forms-uwp-display-pdf

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