1

I'm trying to convert a layout to a PDF. It is full of views from a simple TextView to custom views. Everything works just fine except for the EditText. I see the underline for the EditText but no value.

One attempt is to draw the view directly to a PDF page. This does not work for EditTexts.

activePage = pdfDocument.startPage(pageInfo)
view.draw(activePage.canvas)

Another attempt, and may be the highlighting issue, is trying to convert the view to a bitmap and then draw it. Here's the narrowed down test.

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)

I've tried using EditText, AppCompatEditText, and TextInputEditText. The big kicker worth noting here is that I'm building this view without displaying it to the screen. Here's the full snippet:

// 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)
Sababado
  • 2,524
  • 5
  • 33
  • 51

0 Answers0