实施机器人pdf.js从SD卡读取 [英] Implementing pdf.js in android to read from sd card

查看:1103
本文介绍了实施机器人pdf.js从SD卡读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个PDF浏览器为我的Andr​​oid应用程序而显示不同的PDF文件这是在SD卡present。

I'm trying to implement a pdf viewer for my android app which displays different pdf files which are present in the SD card.

我想用pdf.js的library.I使用code作为样本张贴在这里: https://bitbucket.org/butelo/pdfviewer/

I am thinking of using the pdf.js library.I used the code sample as posted here: https://bitbucket.org/butelo/pdfviewer/

不过,库会在JavaScript文件中的PDF URL是相对地址的文件夹它所属(/资产/ PDF查看器)。

However, the library takes the pdf url in the javascript file which is relative address to the folder to which it belongs (/assets/pdfviewer).

<script type="text/javascript">
var url = '../compressed.tracemonkey-pldi-09.pdf';
</script>

如何可以重定向它在SD卡使用PDF present文件夹中?

How can I redirect it to use a pdf present in a folder in the sdcard ?

另外,PDF的文件名不是固定的,我需要改变他们的计划按要求。

Also the filenames of the pdfs are not fixed and I need to change them in the program as per requirement.

更新--------------------------------------------------------------------------------------------------------------------------

Update --------------------------------------------------------------------------------------------------------------------------

我更新了Java code是这样的:

I updated the java code like this:

Uri path = Uri.parse(Environment.getExternalStorageDirectory().toString() + "/data/test.pdf");
        webView.loadUrl("file:///android_asset/pdfviewer/index.html?file=" + path);

在pdffile.js,我修改了以下内容:

In the pdffile.js, I modified the following:

从:

<script type="text/javascript">
var url = '../compressed.tracemonkey-pldi-09.pdf';
</script>

要:

var url = getURLParameter('file');


function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null}

以上的JavaScript code从提取的URL的'文件'参数'的index.html

The above javascript code extracts the 'file' parameter from the URL of the 'index.html'

还不行。 web视图中的logcat显示'铬':

Still does not work. The webview 'chromium' in logcat shows:

I/chromium(1353): [INFO:CONSOLE(106)] "Warning: Unhandled rejection: 
Unexpected server response (0) while retrieving PDF "file:///storage/sdcard0/data/test.pdf".", source: file:///android_asset/pdfviewer/pdf.js (106)"

这似乎是跨服务器的问题。所以,我怎么可以修改pdf.js code读取本地文件,而无需服务器?

This seems to be cross server issue. So how can I modify the pdf.js code to read local files without server ?

推荐答案

解决这个问题,该应用程序缺少 READ_EXTERNAL_STORAG​​E 的权限。

Solved the issue. The app was missing READ_EXTERNAL_STORAGE permissions.

在code可以在这里找到Android的pdf.js
它的Apache V2许可证,可以随意在你的应用程序中使用。

The code can be found at: https://github.com/pauldmps/Android-pdf.js Its Apache V2 license, so feel free to use in your app.

这篇关于实施机器人pdf.js从SD卡读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆