0

I am trying to execute the below code. But getting this exception:

java.lang.IndexOutOfBoundsException: Index: 11, Size: 11

Does anyone has any idea what is causing this exception and how to resolve it?

 private ByteArrayInputStream getByteArrayInputStream(Document doc) throws DocumentException, IOException {
         InputStream pdfStream = new ByteArrayInputStream(doc.html().getBytes());
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.LETTER);
        PdfWriter writer = PdfWriter.getInstance(document, bytesOut);
        document.open();        
        try{
        XMLWorkerHelper.getInstance().parseXHtml(writer, document, pdfStream, Charset.forName("UTF-8"));
        }       
            catch(IOException ioe){
                System.out.println(ioe.getMessage());
                ioe.printStackTrace();
            }catch(Exception e){
                e.printStackTrace();
            }
        document.close();
        return new ByteArrayInputStream(bytesOut.toByteArray());
    }
Ashwini
  • 125
  • 3
  • 12
  • now, where would this be happening then? – Scary Wombat Nov 18 '16 at 01:36
  • trying to convert a Document to pdf.. – Ashwini Nov 18 '16 at 01:46
  • No, where in this above posted code does it happen? How about posting your stacktrace as well. – Scary Wombat Nov 18 '16 at 01:47
  • Its happening here- XMLWorkerHelper.getInstance().parseXHtml(writer, document, pdfStream, Charset.forName("UTF-8")); I am just getting this in error: Index: 11, Size: 11 java.lang.IndexOutOfBoundsException: Index: 11, Size: 11 – Ashwini Nov 18 '16 at 01:50
  • Without seeing the HTML and without seeing the complete stack trace, there is no way anyone can provide an answer to your question. My guess is that something in your HTML triggers this exception. In any case: I can't reproduce it. Provide a [SSCCE](http://sscce.org) if you expect an answer. If you can't provide one, nobody can answer your question. – Bruno Lowagie Nov 18 '16 at 07:59

1 Answers1

0

I had the same exception. Itext renderer.layout() has problems with empty table rows:

A self-closing <tr/> makes trouble in a table. Please choose if possible this structure instead: <tr><td></td></tr>

Alexander
  • 2,925
  • 3
  • 33
  • 36