Load ONLINE PDF from Server JSON with PdfView library - Android - Java

Load ONLINE PDF from Server JSON with PdfView library - Android - Java:

In this post, you will learn How to Load PDF from Server JSON with PdfView library in Android Studio in Java with RecyclerView.

YouTube Video Tutorial

Step 1 : Add Library

implementation 'com.android.volley:volley:1.2.1'
implementation 'com.squareup.picasso:picasso:2.8'


private class LoadPdfFromURL extends AsyncTask<String, Void, InputStream> {


}
try {
URL url = new URL(pdfUrl);

try {
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
if (httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
return new BufferedInputStream(httpURLConnection.getInputStream());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
if (inputStream != null) {

pdfView.fromStream(inputStream)
.onLoad(new OnLoadCompleteListener() {
@Override
public void loadComplete(int nbPages) {
animationContainer.setVisibility(View.GONE);
pdfViewContainer.setVisibility(View.VISIBLE);
pdfview.setVisibility(View.VISIBLE);
}
})
.enableSwipe(true) // allows to block changing pages using swipe
.swipeHorizontal(false)
.enableDoubletap(true)
.defaultPage(0)
.spacing(10)
.nightMode(false) // toggle night mode
.load();
}
else {
Toast.makeText(PdfViewer.this, "Pdf Load Failed", Toast.LENGTH_SHORT).show();
}
new LoadPdfFromURL().execute(pdfUrl);



Next Post Previous Post
No Comment
Add Comment
comment url