2

I have PDF as an byte array.How to pass byte[] to WebView to display on the screen?
I tried to do it:

byte[] pdfByteArray = getPDFFromServer();
if (pdfByteArray != null && pdfByteArray.length != 0) {
    String base64 = Base64.encodeToString(pdfByteArray, Base64.DEFAULT);
    webView.loadData(base64, "text/html","UTF-8");
}

but it does't work.

Many thanks in advance!

Alex
  • 71
  • 1
  • 6
  • 2
    You are passing the byte array correctly but there's a couple of other problems: 1. WebViews don't display PDF's. 2. text/html is not a pdf. 3 text/html is not base64 encoded. This link shows a way to display a PDF (http://stackoverflow.com/questions/4278422/display-pdf-in-webview) – Dan S Sep 23 '15 at 20:51
  • Didn't work. I receive pdf as an byte array from server. – Alex Sep 25 '15 at 09:27
  • Then I want to convert byte array to pdf and pass it into webView. But i don't know how to do it. – Alex Sep 25 '15 at 09:29

0 Answers0