Click here to Skip to main content
15,851,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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">
    public void onViewCreated(View view, Bundle savedInstanceState) {

        final Button btnGeneraRapportino = (Button)view.findViewById(;
        final WebView img= (WebView) view.findViewById(;

        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
                      String urlString = getActivity().getIntent().getStringExtra(ImageBase64);
                      String mimeType = getActivity().getIntent().getStringExtra("MimeType");
                      WebSettings settings = img.getSettings();
                      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);

Updated 7-Jun-18 0:48am

1 solution

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".
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900