我正在尝试将布局转换为 PDF。它充满了从简单的 TextView 到自定义视图的视图。除了 EditText 之外,一切都很好。我看到 EditText 的下划线,但没有值。
一种尝试是将其view
直接绘制到 PDF 页面。这不适用于 EditTexts。
activePage = pdfDocument.startPage(pageInfo)
view.draw(activePage.canvas)
另一种尝试(可能是突出显示的问题)是尝试将视图转换为位图然后绘制它。这是缩小范围的测试。
val v = view.findViewById<TableRow>(R.id.my_table_row_with_text_and_edittext)
val bitmap = v.drawToBitmap()
activePage.canvas?.drawBitmap(bitmap, 0f, 0f, null)
我尝试过使用 EditText、AppCompatEditText 和 TextInputEditText。值得注意的是,我正在构建这个视图而不将其显示到屏幕上。这是完整的片段:
// pdf page dimensions, big enough to fit the rendered view
val width = 1080
val height = 3000
// inflate the view
val view = layoutInflater.inflate(R.id.pdf_layout, FrameLayout(this), false)
// populate the view with data
applyData(view, model)
// measure and layout the view
view.measure(
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
)
view.layout(0, 0, width, height)