I've implemented this feature using pdfViewer and adding some logic.
I used rxJava2 for multithreading, because Android forbids to use network requests in main thread.
disposables.add(getInputStreamFromUrl(urlResource!!)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
pdfView.fromStream(it)
.defaultPage(0)
.enableSwipe(true)
.autoSpacing(true)
.onLoad {
hideProgressDialog()
}
.onError {
hideProgressDialog()
showInfoDialog(it.message, true)
}
.load()
}, {
hideProgressDialog()
showInfoDialog(it.message, true)
})
)
And getInputStreamFromUrl() method:
private fun getInputStreamFromUrl(url: String): Single<InputStream> {
return Single.defer {
Single.just(URL(url).openStream())
}
}
I hope this will help!