在android上显示base64 pdf到webview [英] Display base64 pdf into webview on android

查看:655
本文介绍了在android上显示base64 pdf到webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi guys I have to view a pdf in base64 in a WebView to do so I used the code below but it does not work! How can I visualize it? I tried this solution but it does not seem to work, nothing is shown in the WebView! What can it be?





我尝试过的方法:





What I have tried:

<pre lang="java">
@Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        final Button btnGeneraRapportino = (Button)view.findViewById(R.id.buttongenera_rapportino);
        final WebView img= (WebView) view.findViewById(R.id.WebView_Rapportino);

        btnGeneraRapportino.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {



                Rapportino r = new Rapportino();
                String ImageBase64 = r.GeneraRapportinoPrivato("prova"); //This method return String with Image into Base64
                  try
                  {
                      String urlString = getActivity().getIntent().getStringExtra(ImageBase64);
                      String mimeType = getActivity().getIntent().getStringExtra("MimeType");
                      WebSettings settings = img.getSettings();
                      settings.setDefaultTextEncodingName("utf-8");
                      String base64 = Base64.encodeToString(urlString.getBytes(), Base64.DEFAULT);
                      img.loadData(urlString, "text/html; charset=utf-8", "base64");
                }
                catch (Exception ex){
                    System.out.print("Errore: "+ex);
                }
            }
        });


    }

推荐答案

WebView 不支持显示PDF文件(除了使用Google Docs查看器等外部服务,需要PDF文件的URL)。你必须选择另一种方法。只需在网上搜索android show pdf。
WebView does not support showing PDF files (besides using external services like the Google Docs viewer which requires an URL to the PDF file). You have to choose another method. Just search the web for something like "android show pdf".


这篇关于在android上显示base64 pdf到webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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