Android Question Loading/Displaying PDF in Webview with ContentChooser problem

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I want the user to be able to
  1. select a PDF file from their local storage,
  2. display a preview of the PDF file
  3. and then upload the file to a remote server.

I have all of this working fine with B4i using the code from and multipart post. However, I have run into problems with B4A.

I have modified (slightly) the code from this tutorial to demonstrate the first part problem I am having:

I can select a file, however, I cannot then display it in a webview nor can I upload it using multipart post. Strangely, the ReadString function works fine.

I am using LoadUrl on the Webview to display the PDF.
'            WebView1.loadurl(File.combine(Result.dir,Result.filename))

Page Finished show that the webview thinks it has loaded the file.

private Sub webview1_PageFinished (Url As String)$"Finished loading ${Url}"$)
    Log($"Finished loading ${Url}"$)
End Sub
The commented out line just gives a file not found error.

Finished loading file://contentdir/

Any ideas what I am doing wrong?

FYI I am testing on a Samsung Galaxy Tab A


    184.4 KB · Views: 104

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
1. Android WebView doesn't support PDF documents.
2. Don't use FileUri with this url. Result.filename is the url.

Ah, that would explain it.

I try give PDFium to view the PDF instead,, as I would prefer to have the PDF in a view rather than call an intent which would be full screen.

So using Multipart post to upload the file to a server,

is it ?
    Dim mp As MultipartFileData
    mp.Dir = result.dir
    mp.FileName = result.filename
Upvote 0