DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.05k stars 1.85k forks source link

unable to load pdf from json api using pdfView.fromUri(Uri) #997

Open kaarthik1999 opened 3 years ago

kaarthik1999 commented 3 years ago

val pdfUrl=bookJsonObject.getString("pdf") val uri=Uri.parse(pdfUrl) pdfView.fromUri(uri) The above is my kotlin code I am using implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'

rounaksingh1694 commented 3 years ago

I am also facing a similar issue. I am unable to display pdf from firebase

NikDev9 commented 3 years ago

To display a pdf from firebase storage:

Suppose your pdf file path in the storage is "pdfs/book1.pdf"

Kotlin code:

  1. Storage reference val storage: FirebaseStorage = FirebaseStorage.getInstance() val storageRef = storage.reference.child("pdfs/book1.pdf")

  2. Create a temporary file and store pdf from the storage in it and load using pdfViewer

    val localFile = File.createTempFile("book", "pdf")
    storageRef.getFile(localFile).addOnSuccessListener {
        pdfViewer.fromFile(localFile).load()
    }