0

我想我快到了,但是...

我已经将 a 包裹com.github.barteksc.pdfviewer.PDFView在一个可组合的组件中,如下所示:

@Composable
fun PDFView(
    byteArray: ByteArray
) {
    AndroidView(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.Red),

        factory = { context ->
            PDFView(context, null)
        },
        update = { pdfView ->
            Log.d(TAG, "PDF view UPDATE called")
            pdfView.fromBytes(byteArray)
            Log.d(TAG, "Page Count: ${pdfView.pageCount}")
            Log.d(TAG, String(bytes = byteArray))
        }
    )
}

但是,我只是在调用视图时没有看到显示的 PDF,如下所示:

    val context = LocalContext.current
    val filename = "example.pdf"
    val fileInputStream = context.assets.open(filename)
    val byteArray = fileInputStream.readBytes()
    
    PDFView(byteArray = byteArray)

现在,我知道 PDF 存在,因为回调的Log.d输出update确实产生了原始 PDF 内容。但是,Page Count日志输出显示 0 页。

我错过了什么?为什么不显示 PDF?

更新

弄清楚了。您需要.load()像这样添加:

    pdfView
        .fromBytes(byteArray)
        .load()
4

0 回答 0