如何将PDF嵌入HTML并在Web视图中显示? 实际上我正在尝试这个,但webview没有加载这个页面。
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String pdfPath = base + "/Principal.pdf";
Log.e("real path =", ""+pdfPath);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setAllowFileAccess(true);
web.getSettings().setBuiltInZoomControls(true);
web.loadDataWithBaseURL("",
"<embed src='"+pdfPath+"' width='500' height='375'>",
"application/pdf",
"utf-8",
"");
答案 0 :(得分:0)
愿它有用:
String myPdfUrl = "http://example.com/awesome.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
Log.i(TAG, "Opening PDF: " + url);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
try
{
Intent intentUrl = new Intent(Intent.ACTION_VIEW);
intentUrl.setDataAndType(url, "application/pdf");
intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
myActivity.startActivity(intentUrl);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(myActivity, "No PDF Viewer Installed", Toast.LENGTH_LONG).show();
}