简体   繁体   English

android:从我的应用程序打开一个pdf,而不使用pdf查看器

[英]android: open a pdf from my app without using pdf viewer

I want to be able to open a pdf file from my application without any other application like pdf viewer. 我希望能够在没有任何其他应用程序(如pdf viewer)的情况下从我的应用程序打开pdf文件。 I don't want to make the user install an other appliation to open pdf files. 我不想让用户安装其他应用程序来打开pdf文件。 Is there any open source library that I can use in my project? 我可以在项目中使用任何开源库吗?

You can open a PDF in a webview using google docs. 您可以使用Google文档在网页浏览中打开PDF。 The URL format is URL格式是

https://docs.google.com/gview?embedded=true&url=http://link.to.your/pdf_file.pdf

You can use, for instance, MuPdf Reader. 例如,您可以使用MuPdf Reader。 I described how to build it here . 在这里描述了如何构建它。

You can open a PDF in a webview using google docs. 您可以使用Google文档在网页浏览中打开PDF。 The URL format is URL格式是

https://docs.google.com/gview?embedded=true&url=http://link.to.your/yourfile.pdf https://docs.google.com/gview?embedded=true&url=http://link.to.your/yourfile.pdf

or you can open pdf using pdf viewer Follow this code 或者您可以使用pdf viewer打开pdf请遵循以下代码

            FileFinalpath = SdCardpath + "/" + Filepath + Filename;
            File file = new File(FileFinalpath);
            if (file.exists()) {
                Uri filepath = Uri.fromFile(file);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(filepath, "application/pdf");
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                try {
                    startActivity(intent);
                } catch (Exception e) {
                    alert.showAlertDialog(PDF_Activity.this, "File Not Started...","File Not Started From SdCard ", false);             
                    Log.e("error", "" + e);
                }

            } else {
                alert.showAlertDialog(PDF_Activity.this, "File Not Found...","File Not Found From SdCard ", false);             

            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM