我收到一個 PDF 檔案的編碼 base64 字串,我想將它顯示在一個帶有浮動操作按鈕的片段中,該按鈕可用于保存或列印 pdf。
我已經嘗試過
uj5u.com熱心網友回復:
我能夠通過使用這個庫來解決我的問題
將以下內容添加到您的 build.gradle
implementation 'com.github.mhiew:android-pdf-viewer:3.2.0-beta.1'
將以下內容添加到您的布局中
<com.github.barteksc.pdfviewer.PDFView
android:id="@ id/pdfView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_bar" />
然后簡單地解碼base64字串并將其傳遞給pdfView,如下所示
private fun renderPdf(base64EncodedString: String) = try {
val decodedString = Base64.decode(base64EncodedString, Base64.DEFAULT)
binding.pdfView.fromBytes(decodedString).load()
} catch (e: Exception) {
// handle error
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/358582.html
上一篇:Python-將標頭插入csv
下一篇:提取pdf矢量物件
