How To Open Pdf File In External App Or In Webview Size Is Greater Than 25mb
hello i want to show pdf file in webview or in external app. 1) i use this url https://docs.google.com/gview?embedded=true&url= +pdfurl , but google says 'Whoops There was a p
Solution 1:
To show it in WebView try something like this
Stringpdf="http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
To show it in browser try something like this
IntentbrowserIntent=newIntent(Intent.ACTION_VIEW, Uri.parse(pdf_url));
startActivity(browserIntent);
Solution 2:
If your files are in assets first copy them to the external storage. Hope that you have handled permission flow.
Try the following code for offline
FilepdfFile=newFile(Environment.getExternalStorageDirectory(),"pdfName.pdf");//Pdf file pathif (pdfFile.exists()) //Checking for the file is exist or not
{
Uripath= Uri.fromFile(pdfFile);
IntentobjIntent=newIntent(Intent.ACTION_VIEW);
objIntent.setDataAndType(path, "application/pdf");
objIntent.setFlags(Intent. FLAG_ACTIVITY_CLEAR_TOP);
startActivity(objIntent);//Staring the pdf viewer
} else {
Toast.makeText(getActivity(), "The file not exists! ", Toast.LENGTH_SHORT).show();
}
Try the following for the webview option if you choose that
WebViewwebview= (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
Stringpdf="online pdf link";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
But Remember if you use google docs for viewing the pdf or any other doc, google docs may throw you the error stating
You've reached the bandwidth limit for viewing or downloading files that aren't in Google Docs format..... So doesn't seem reliable
So, be cautious with google doc viewing
Post a Comment for "How To Open Pdf File In External App Or In Webview Size Is Greater Than 25mb"