0

I am getting a pdf document as an attachment from a POST call. But I am not able to display the pdf in android webview directly. I could download the file in local storage. But due to security reasons, instead of downloading it, I need to display it within the webview itself.

I have tried several solutions :

  1. Displaying using google docs / drive - It gives "No Preview Available" on the webview (The reason for this might be that I don't receive a pdf url in response. What I receive is the pdf document as an attachment mentioned in the POST call response as "Content-Disposition" "attachment; filename=abc.pdf".

  2. Tried using the intent view, but nothing happens on click of the link for pdf in webview. webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); } });

Is there any other way to achieve this without downloading the pdf in external storage and directly open the attachment from POST response into android webview.

Anji
  • 36
  • 4
  • The LEADTOOLS Android [Viewer](https://www.leadtools.com/sdk/display) SDK can display a PDF from a stream. You can use the [LeadStream.Factory](https://www.leadtools.com/help/sdk/dh/l/leadstream-factory.html) helper class to load the PDF into a stream without having to download it and then render it in the viewer. (Disclaimer: I am an employee of the vendor) – Hussam Barouqa Mar 02 '23 at 17:38

0 Answers0