我正在尝试使用webview从网址显示PDF . 我尝试使用src属性和url属性加载它 . 我也尝试从Javascript中的onLoaded事件加载它,但仍然没有运气...有没有更好的方法在Nativescript应用程序中加载PDF文档? webview会加载像google网址一样小的内容,但不会出现任何问题 . 这是我尝试过的一些代码 .
// did not work
<WebView row="0" id="eula-view" src="https://somewebsite/eula/foo.pdf"/>
// did not work
<WebView row="0" id="eula-view" url="https://somewebsite/eula/foo.pdf" />
//worked fine
<WebView row="0" id="eula-view" url="http://google.com" />
从JS而不是从xml加载
//did not work
exports.viewLoaded = function (args) {
var page = args.object;
var webview = page.getViewById("eula-view");
webview.url = "https://somewebsite/eula/foo.pdf";
};
// worked fine
exports.viewLoaded = function (args) {
var page = args.object;
var webview = page.getViewById("eula-view");
webview.url = "http://google.com";
};
1 回答
我个人尝试使用Google Docs进行
WebView
方法,因为我需要从本地设备显示PDF文件,并且不希望需要有效的Internet连接 .该插件是nativescript-pdf-view . 用法是这样的:
Plain NativeScript:
Angular 2