1

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?

Java Code:

@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 pdf 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); } } }); } 
11
  • Do you want to display from URL or local? Commented Jun 7, 2018 at 6:57
  • @MilanPansuriya the r.GeneraRapportinoPrivato(..) method returns a base64 string from a node.js server, I would like to show the pdf locally in a WebView Commented Jun 7, 2018 at 7:00
  • for webview you have pdf file url or are you display from assets folder? Commented Jun 7, 2018 at 7:01
  • @MilanPansuriya he say he got base64 image of pdf file, so the process is to convert base64 string to image file, save to local or temp folder then show it to webview Commented Jun 7, 2018 at 7:03
  • @RandykaYudhistira exact is a pdf file not an image! Commented Jun 7, 2018 at 7:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.