在web视图加载PDF格式,而离线 [英] load pdf in webview while offline

查看:181
本文介绍了在web视图加载PDF格式,而离线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何嵌入PDF文件转换为HTML并显示在Web视图? 其实我想这一点,但web视图不会加载这个页面。

 字符串基地= Environment.getExternalStorageDirectory()getAbsolutePath()的toString()。
            字符串pdfPath =基地+/Principal.pdf;
             Log.e(真实路径=,+ pdfPath);
            web.getSettings()setJavaScriptEnabled(真)。
            。web.getSettings()setAllowFileAccess(真正的);
            。web.getSettings()setBuiltInZoomControls(真正的);
            web.loadDataWithBaseURL(,
                    <嵌入的src ='+ pdfPath +WIDTH =500高度='375'>中,
                    应用程序/ PDF格式,
                    UTF-8,
                    );
 

解决方案

也许这将是有益的:

进行在线:

 字符串myPdf​​Url =htt​​p://example.com/awesome.pdf;
字符串URL =htt​​p://docs.google.com/gview?embedded=true&url=+ myPdf​​Url;
Log.i(TAG,打开PDF:+网址);
webView.getSettings()setJavaScriptEnabled(真)。
webView.loadUrl(URL);
 

进行脱机:

 尝试
{
 意图int​​entUrl =新的意图(Intent.ACTION_VIEW);
 intentUrl.setDataAndType(URL,应用程序/ PDF格式);
 intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 myActivity.startActivity(intentUrl);
}
赶上(ActivityNotFoundException E)
{
 Toast.makeText(myActivity,没有PDF浏览器安装,Toast.LENGTH_LONG).show();
}
 

How to Embed a PDF into HTML and show it in web view ? Actually i am trying this but webview not loaded this page.

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

解决方案

May it will be helpful:

For ONLINE:

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

For OffLine:

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

这篇关于在web视图加载PDF格式,而离线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆