我已将 pdf.js 添加到我的 Android 项目(Visual Studio 2015,Xamarin)中,以在 WebView 组件中显示 pdf。使用以下 Cod 加载示例 pdf。
WebView wv = FindViewById<WebView>(Resource.Id.webView1);
wv.SetWebChromeClient(new WebChromeClient());
wv.Settings.JavaScriptEnabled = true;
wv.Settings.AllowUniversalAccessFromFileURLs = true;
wv.LoadUrl("file:///android_asset/pdfviewer/viewer.html?file=http://www.orimi.com/pdf-test.pdf");
但是,一旦我尝试向下滚动 pdf,整个应用程序就会崩溃。以下行来自调试日志。
加载的程序集:System.dll [外部] Der Thread 'Unknown' (0x2) hat mit Code 0 (0x0) geendet。01-08 11:41:48.763 W/cr.BindingManager(5994):无法调用确定可见性()-从未看到 pid 的连接:5994 [INFO:CONSOLE(0)]“提供的值'moz-chunked-arraybuffer ' 不是 XMLHttpRequestResponseType 类型的有效枚举值。”,来源:(0) 01-08 11:41:49.359 I/chromium(5994): [INFO:CONSOLE(0)] “提供的值 'moz-chunked- arraybuffer' 不是 XMLHttpRequestResponseType 类型的有效枚举值。”,来源:(0)[INFO:CONSOLE(946)]“未捕获(承诺中)TypeError:无法读取属性'getItem' of null”,来源:文件:/ //android_asset/pdfviewer/viewer.js (946) 01-08 11:41:49.540 I/chromium(5994): [INFO:CONSOLE(946)] "http://www.orimi.com/pdf-test.pdf (0) 01-08 11:41:49.565 W/cr.BindingManager(5994):无法调用确定可见性() - 从未看到 pid 的连接:5994 01-08 11:41:49.565 I/chromium(5994):[INFO:CONSOLE(0)]“处理程序添加到拒绝的承诺”,来源:file:///android_asset/pdfviewer/viewer.html?file= http: //www.orimi.com/pdf-test.pdf(0)[INFO:CONSOLE(7007)]“TypeError:无法读取null的属性'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js(7007)01-08 11:41:49.566我/chromium(5994):[INFO:CONSOLE(7007)]“TypeError:无法读取null的属性'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js(7007)[INFO:CONSOLE(946 )] “未捕获(承诺中)类型错误:无法读取 null 的属性 'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js (946) 01-08 11:41:49.607 I/chromium(5994 ):[INFO:CONSOLE(946)]“未捕获(承诺)TypeError:无法读取null的属性'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js(946)[INFO:CONSOLE( 7104)] "PDF c21f21ea44c1e2ed2581435fa5a2dcce [1.6 Acrobat Distiller 7.0.5 (Windows) / Acrobat PDFMaker 7.0。7 for Word] (PDF.js: 1.2.109)”,来源:file:///android_asset/pdfviewer/viewer.js (7104) 01-08 11:41:49.607 I/chromium(5994): [信息: CONSOLE(7104)] “PDF c21f21ea44c1e2ed2581435fa5a2dcce [1.6 Acrobat Distiller 7.0.5 (Windows) / Acrobat PDFMaker 7.0.7 for Word] (PDF.js: 1.2.109)”,来源:file:///android_asset/pdfviewer/viewer .js(7104)[INFO:CONSOLE(946)]“未捕获(承诺)TypeError:无法读取属性'getItem' of null”,来源:file:///android_asset/pdfviewer/viewer.js(946)01- 08 11:41:49.667 I/chromium(5994):[INFO:CONSOLE(946)]“未捕获(承诺中)TypeError:无法读取属性'getItem' of null”,来源:file:///android_asset/pdfviewer/查看器.js (946)[INFO:CONSOLE(7104)]“PDF c21f21ea44c1e2ed2581435fa5a2dcce [1.6 Acrobat Distiller 7.0.5 (Windows) / Acrobat PDFMaker 7.0.7 for Word] (PDF.js: 1.2.109)”,来源:file:///android_asset/ pdfviewer/viewer.js (7104) [INFO:CONSOLE(946)]“未捕获(承诺)类型错误:无法读取 null 的属性 'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js(946 ) 01-08 11:41:49.667 I/chromium(5994):[INFO:CONSOLE(946)]“未捕获(承诺中)类型错误:无法读取 null 的属性 'getItem'”,来源:file:///android_asset /pdfviewer/viewer.js (946)[INFO:CONSOLE(7104)]“PDF c21f21ea44c1e2ed2581435fa5a2dcce [1.6 Acrobat Distiller 7.0.5 (Windows) / Acrobat PDFMaker 7.0.7 for Word] (PDF.js: 1.2.109)”,来源:file:///android_asset/ pdfviewer/viewer.js (7104) [INFO:CONSOLE(946)]“未捕获(承诺)类型错误:无法读取 null 的属性 'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js(946 ) 01-08 11:41:49.667 I/chromium(5994):[INFO:CONSOLE(946)]“未捕获(承诺中)类型错误:无法读取 null 的属性 'getItem'”,来源:file:///android_asset /pdfviewer/viewer.js (946)未捕获(承诺)类型错误:无法读取 null 的属性“getItem”,来源:file:///android_asset/pdfviewer/viewer.js(946)01-08 11:41:49.667 I/chromium(5994):[信息:控制台(946)]“未捕获(承诺)类型错误:无法读取 null 的属性 'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js(946)未捕获(承诺)类型错误:无法读取 null 的属性“getItem”,来源:file:///android_asset/pdfviewer/viewer.js(946)01-08 11:41:49.667 I/chromium(5994):[信息:控制台(946)]“未捕获(承诺)类型错误:无法读取 null 的属性 'getItem'”,来源:file:///android_asset/pdfviewer/viewer.js(946)
这是 viewer.js 函数的片段(第 946 行)
_readFromStorage: function ViewHistory_readFromStorage() {
return new Promise(function (resolve) {
resolve(localStorage.getItem('database')); (Line 946)
});
},
有人有想法吗?