Android - 将额外的 pdf 页面附加到 PrintedPdfDocument

问题描述

在我的应用程序中,我将一些部分打印为用户的 pdf。我通过使用 PrintedPdfDocument 来做到这一点。

代码如下所示:

    // create a new document
    val printAttributes = PrintAttributes.Builder()
            .setMediaSize(mediaSize)
            .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
            .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
            .build()
    val document = PrintedPdfDocument(context,printAttributes)

    // add pages
    for ((n,pdfPageView) in pdfPages.withIndex()) {
        val page = document.startPage(n)
        Timber.d("Printing page " + (n + 1))
        pdfPageView.draw(page.canvas)
        document.finishPage(page)
    }

    // write the document content
    try {
        val out: OutputStream = FileOutputStream(outputFile)
        document.writeTo(out)
        out.close()
        Timber.d("PDF written to $outputFile")
    } catch (e: IOException) {
        return
    }

一切正常。但是现在我想在最后添加另一个页面。唯一的例外是这将是从资产中预先生成的 pdf 文件。 我只需要附加它所以不需要额外的渲染等。

有没有办法通过 Android SDK 中的 PdfDocument 类来做到这一点?

https://developer.android.com/reference/android/graphics/pdf/PdfDocument#finishPage(android.graphics.pdf.PdfDocument.Page)

我认为这可能是一个类似的问题:how can i combine multiple pdf to convert single pdf in android?

但这是真的吗?答案没有被接受,已经3岁了。有什么建议吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)