View PDF in WebView

2

I'm developing an application for a Clinical Analysis Lab. It has an online system where you can view the results.

On the site, it has a list of all the exams of the client and when I click on the link to open the exam, it loads a PDF in a new tab, this through the Desktop. By Mobile, when I click on it, it appears to open a blank tab in WebView, but it does not load any PDF, without downloading the PDF.

My Code:

wv = (WebView) findViewById(R.id.webViewResultados);

    WebSettings ws = wv.getSettings();
    ws.setJavaScriptEnabled(true);
    ws.setSupportZoom(false);
    ws.setAllowFileAccess(true);

    wv.loadUrl("http://187.17.196.42:8181/ConcentWeb/servlet/hlab8000");
    wv.setWebViewClient(new WebViewClient());
    
asked by anonymous 07.07.2017 / 14:44

2 answers

1

Option 1

Use Google's viewer . Here's how it should look:

WebView ws = (WebView) findViewById(R.id.webview);
ws.getSettings().setJavaScriptEnabled(true); 
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
ws.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);

Note: It's important to note the usage limit for Google Drive.

Option 2

Use pdf.js , open-source project of Mozila , which is perhaps the most viable option since it has no use limit. Just download and copy the project to your assets . Take a look at Viewer options for more options beyond the basics. See below how it would look:

String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";

webview = (WebView) findViewById(R.id.webview);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setBuiltInZoomControls(true);
webview.setWebChromeClient(new WebChromeClient());
webview.loadUrl("file:///android_asset/pdfjs/web/viewer.html?file=" + pdf  + "#zoom=page-width");
    
07.07.2017 / 17:13
0

You can try opening the PDF with Google Drive, / a>

PS: Within the web view, using ionic + inappBrowser worked for something I needed

    
07.07.2017 / 15:35