How to render a PDF file in Android

后端 未结 9 1058
猫巷女王i
猫巷女王i 2020-11-22 02:09

Android does not have PDF support in its libraries. Is there any way to render PDF files in the Android applications?

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 02:42

    To add a little light to this, I would have to go with the pdf.js solution from Mozilla. Here is the link to an already well written implementation of this: https://bitbucket.org/butelo/pdfviewer/.

    Here are the edits that I added in my Android Activity:

    private String getInternalPDFURL(String interalPDFName){
        return "file:///android_asset/pdfviewer/index.html?pdf=" + interalPDFName + ".pdf";
    }
    

    Here are the edits I made in pdffile.js:

    var url = '../' + getPDFURL();
    
    function getPDFURL(){
        var query = window.location.search.substring(1);
        var vars = query.split("=");
        var pdfPage = vars[1];
        return pdfPage;
    }
    

提交回复
热议问题