Page 1 of 1

Table rendering failure converting to PDF

PostPosted: Fri Apr 19, 2013 4:09 am
by ham_360
I have found that the PDF converter is failing to render all tables. I will paraphrase my findings here:

In org.docx4j.model.table.TableModel.handleRow, I am for every table, hitting the 'log.warn' line below:
Code: Select all
private void handleRow(NodeList cellContents, Tr tr, int r) {
   //...
   for (Tc tc : tcFinder.tcList) {
      Node wtrNode = cellContents.item(r); // w:tr
      if (wtrNode==null ) {
         log.warn("Couldn't find item " + r);
      }
      addCell(tc, getTc(wtrNode, c, new IntRef(0)));
      //...
   }
}

This then breaks the code in the next line, since getTc() is being passed a value of 'wtrNode==null' and can't then run wtrNode.getChildNodes().getLength()
Code: Select all
private Node getTc(Node wtrNode, int wanted, IntRef current) {
   for (int i=0; i<wtrNode.getChildNodes().getLength(); i++ ) {
      //...


wtrNode is calculated by 'cellContents.item(r)' (Note, both 'cellContents' and 'r' are both passed as parameters and are not used anywhere else within the function or sub-functions, so it would be best to not only pull the 'Node wtrNode = ...' line outside the 'for' loop, but also change the parameters to handleRow(Node wtrNode, Tr tr) and have wtrNode calculated by any calling function). handleRow is called by 'build'. 'r' is a counter of the number of table rows found by TraversalUtil on a w:tbl, and cellContents is the NodeList version of these rows.
Code: Select all
public void build(Tbl tbl, Node content) throws TransformerException {
   //...
   NodeList cellContents = content.getChildNodes(); // the w:tr
   
   TrFinder trFinder = new TrFinder();
   new TraversalUtil(tbl, trFinder);
   
   int r = 0;
   for (Tr tr : trFinder.trList) {
         startRow();
         handleRow(cellContents, tr, r);
         r++;
   }
}


Essentially, what's happening here is:
Code: Select all
trFinder.trList.size() == (cellContents.getLength() + 1)
//resulting in...
cellContents.item(r) == null
//where r=trFinder.trList.size);


I wonder whether the problem lies with TraversalUtil, its params, or content...?

In any case i'm giving up on this front for now!

Re: Table rendering failure converting to PDF

PostPosted: Fri Apr 19, 2013 9:54 pm
by jason
Could you please post a sample docx which exhibits the issue? thanks..

Re: Table rendering failure converting to PDF

PostPosted: Tue Apr 23, 2013 2:40 am
by ham_360
Hi Jason,

Thanks for getting back to me. I have in the meantime narrowed it down to all tables containing tables (such as the attached document).

The error produced is this:
[main] WARN org.docx4j.model.table.TableModel - Couldn't find item X
[main] ERROR org.docx4j.convert.out.Converter - Cannot convert [w:tbl: null] java.lang.NullPointerException
at org.docx4j.model.table.TableModel.getTc(TableModel.java:539)

Re: Table rendering failure converting to PDF

PostPosted: Tue Apr 23, 2013 8:06 am
by jason
ham_360 wrote:I have in the meantime narrowed it down to all tables containing tables (such as the attached document).


I've tried your nested table tester.docx using current docx4j nightly, and it works for me.

The rendering is imperfect, in that you can see the outer table:

pdf_nested_table.png
pdf_nested_table.png (8.98 KiB) Viewed 1812 times


but that's a different issue.

So I guess the source code you analysed is not the current master at https://github.com/plutext/docx4j/

You can download a current nightly from http://www.docx4java.org/docx4j/

Re: Table rendering failure converting to PDF

PostPosted: Tue Apr 23, 2013 11:39 pm
by ham_360
Correct - I've been using the last full release. Indeed, using the latest nightly build it renders. I bet you must be sick of that response! Any ideas when the next full release will be?
Thanks.

Re: Table rendering failure converting to PDF

PostPosted: Wed Apr 24, 2013 7:23 am
by jason
I think we'll start the release process in May. Hopefully finish it then as well :-)

I'm waiting on 3 externalities, none of which are critical, but all of which would be nice to include.

cheers .. Jason