I finally was able to modify butelo's code to open any PDF file in the Android filesystem using pdf.js
. The code can be found on my GitHub
What I did was modified the pdffile.js
to read HTML argument file
like this:
var url = getURLParameter('file');
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null}
So what you need to do is just append the file path after the index.html
like this:
Uri path = Uri.parse(Environment.getExternalStorageDirectory().toString() + "/data/test.pdf");
webView.loadUrl("file:///android_asset/pdfviewer/index.html?file=" + path);
Update the path
variable to point to a valid PDF in the Adroid filesystem.