Convert binary content of pdf file in android (kotlin)

971 views Asked by At

I am getting a response from the server which starts from %PDF-1.7. I believe that it is a base64 string(correct if I am wrong). Now while decoding the data using kotlin I am getting an error.What I want to achieve is I want to parse the response and open it into a pdfviewer.Help is appreciated.Thank you.

1

There are 1 answers

0
Chinmaay On BEST ANSWER

To all those who are still stuck in this.I have cracked this in the below way

Summary before I start

  1. I have used volley string request.
  2. I have used third party library implementation 'com.github.barteksc:android-pdf-viewer:2.8.2

Layout file

 <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfViewer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"/>

Kotlin code

 override fun parseNetworkResponse(response: NetworkResponse): Response<String?>? {
                val data = response.data
                return super.parseNetworkResponse(response)
            }

and then in your response listener

 binding?.pdfViewer?.fromBytes(data)?.load()

Happy coding.