Problem with table overflow

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for Java (v6)  /  Problem with table overflow

DynamicPDF Generator for Java (v6) Forum

 Aug 20 2012 6:53 PM
I am having an error when i try using the getOverflowRows() method for tables. I first check if the table can fit on the current page, if it cant then I use the overflow. the PDF is generated and looks awesome when the table fits on the page, but when it has to overflow the PDF is not generated and the logcat shows these errors showing up when the Report.write method is run.

08-20 13:47:03.791: W/System.err(3602): java.lang.NullPointerException
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.pageelements.Group.draw(Unknown Source)
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.Page.drawAppend(Unknown Source)
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.Page.drawEntries(Unknown Source)
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.Page.draw(Unknown Source)
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.io.n.h(Unknown Source)
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.io.n.draw(Unknown Source)
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.Document.draw(Unknown Source)
08-20 13:47:03.801: W/System.err(3602):         at com.cete.dynamicpdf.Document.draw(Unknown Source)


here is the section of the code I think I'm having the problem with. ptables is an arraylist of tables, and pages is an arraylist of the pages, and vPos is the Y coordinate that the next element should be placed at, the rest should be easy to figure out.


// set height of first table to whats remaining on the page and then add it to the page
ptables.get(ptables.size() - 1).setHeight(pageHeight - vPos);
pages.get(currentPage).getElements().add(ptables.get(ptables.size() - 1));

// start new page
vPos = 0;
report.getPages().add(pages.get(currentPage));
pages.add(new Page(PageSize.LETTER, PageOrientation.PORTRAIT, 54.0f));
currentPage++;

// calculate height needed for the overflow table then create and add it
overflowHeight = (int) (ptables.get(ptables.size() - 1).getRequiredHeight() - ptables.get(ptables.size() - 1).getHeight() + 50);
Table2 overflow = ptables.get(ptables.size() - 1).getOverflowRows(0, vPos, 500, overflowHeight);
vPos += overflowHeight + 5;
pages.get(currentPage).getElements().add(overflow);



I had a similar error before because I had forgotten to set the column size of the tables, but the sample code didn't show setting the columns for overflow tables so I'm lost as to what I'm doing wrong. thanks in advance for any help.
 Aug 21 2012 5:10 AM
Posted by a ceTe Software moderator
Hello,

Please try using the latest DynamicPDF jar file in your application and see if it works for you. You can download latest v6.x jar file by logging into our CustomerArea using your version 6 product serial number. Remove reference for the old jar file and reference the latest DynamicPDF jar file in your application.

It is suggested to check the Table for overflow rows using hasOverflowRows method which returns a value indicating if there are rows remaining that will not be drawn to the table. Then you can set any dimensions to it and add it to page. Please make sure that you are always adding a table object to page having rows in it and this will work for you.

Thanks,
ceTe Software Support Team.
 Aug 21 2012 1:46 PM
Thanks, using hasOverflowRows fixed the problem. I was also trying to calculate the height manually but I found getRequiredHeight and between those two methods everything is working out great.

All times are US Eastern Standard time. The time now is 1:32 PM.