4

I am trying to test with Robolectric or AndroidJUnit4 some pdf generation in my android application (using android.graphics.pdf.PdfDocument).

@Test
fun testPdfDocument() {
    val doc = PdfDocument()
    val builder = PdfDocument.PageInfo.Builder(20, 10, 1)
    val pdf = builder.create()
    assertEquals(0, doc.pages.size)
    val page = doc.startPage(pdf) // java.lang.IllegalStateException: document is closed!
    doc.finishPage(page)
    assertEquals(1, doc.pages.size)
}

The code above crashes, with java.lang.IllegalStateException: document is closed!. Any idea why?

XAM
  • 109
  • 1
  • 4
  • N.B.: I abstracted my app code to only have the critical part that fails. See more PdfDocument tests here: https://android.googlesource.com/platform/cts/+/master/tests/pdf/src/android/graphics/pdf/cts/PdfDocumentTest.java – XAM Dec 09 '19 at 10:20
  • I also tried using `PrintedPdfDocument` instead but I had the same issue. – XAM Dec 09 '19 at 15:26
  • I have the same problem. Please, notify if you will have found any decision. Thank you! – Andrew G Dec 09 '19 at 16:55
  • I receive the following error: java.lang.UnsatisfiedLinkError: android.graphics.pdf.PdfDocument.nativeCreateDocument()J during PdfDocument. Do.you have the same problem? – xcesco Apr 05 '20 at 23:37
  • Mine is : `java.lang.IllegalStateException: document is closed!` – XAM Apr 08 '20 at 08:34
  • I'm facing the same problem. Any updates? – Nishant Mittal Jul 05 '22 at 18:53

0 Answers0