I am trying to create a PDF on Android but only to show some information when I press a button, not to store it on the mobile phone. I am getting this error:
Unhandled exception: com.itextpdf.text.DocumentException
but I do not understand why it happens. I have the following code:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument pdf = new PdfDocument();
PdfWriter pdfWriter = PdfWriter.getInstance(pdf, baos); //Error here
pdf.open();
pdf.add(new Paragraph("Hello world")); //Error here
pdf.close();
byte[] pdfByteArray = baos.toByteArray();
Why I am getting this error? Am I using the itextg library incorrectly? I could not find any information about this error.
P.S.: I could see that the error is related with itext
instead of itextg
so I do not know if the error can be produced with this fact.
Thanks in advance!