简体   繁体   中英

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. I don't want to make the user install an other appliation to open pdf files. Is there any open source library that I can use in my project?

You can open a PDF in a webview using google docs. The URL format is

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

You can use, for instance, MuPdf Reader. I described how to build it here .

You can open a PDF in a webview using google docs. The URL format is

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

            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);             

            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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