gpt4 book ai didi

android - 离线时在 webview 中加载 pdf

转载 作者:太空狗 更新时间:2023-10-29 15:04:05 24 4
gpt4 key购买 nike

如何将 PDF 嵌入到 HTML 中并在 Web View 中显示?其实我正在尝试这个,但是 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",
"");

最佳答案

希望对您有所帮助:

对于在线:

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

关于android - 离线时在 webview 中加载 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23556693/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com