java - iText tables - how to keep multi row cells on one page? -
i'm creating table in itext lists events date. if there mutliple events date, set rowspan property of date-cell number of events. i'm using row each event, since want display additional info event , want keep aligned. basicly table can this:
date | event | details --------+-----------+--------------- date 1 | event 1 | details 1 --------+-----------+--------------- date 2 | event 2 1 | more | | details 2 1 +-----------+--------------- | event 2 2 | details 2 2 --------+-----------+---------------
the cell containing date 2
has rowspan of 2.
i add table using columntext.go()
in loop.
if write table document , there enough space left event 2 1
, event 2 2
goes new page. how can force new page before adding date 2
?
using pdfptable.setsplitlate(true)
doesn't seem affect multi row cells. neither setting fixed height of date 2
cell combined heights of 2 rows.
one solution use nested tables column 2 , 3 (and treat column 2 , 3 1 column)
another solution, doesn't work correctly in version of itext i'm using use
pdfptable.writeselectedrows()
, write (combined) rows fit on page. problem is, way row span ignored ,date
cells tey span 1 row.
are there other ways?
you create table each row , use pdfptable.setkeeptogether(true)
works in itext 2.1.7, though wouldn't recommend staying version. here example, outputfile
file type variable pdf file being created.
document document = new document(new rectangle(620, 150)); pdfwriter.getinstance(document, new fileoutputstream(outputfile)); document.open(); pdfptable headerrow = new pdfptable(3); headerrow.setkeeptogether(true); headerrow.addcell("date"); headerrow.addcell("event"); headerrow.addcell("details"); pdfptable firstrow = new pdfptable(3); firstrow.setkeeptogether(true); firstrow.addcell("date 1"); firstrow.addcell("event 2 1"); firstrow.addcell("more\ndetails 2 1"); pdfptable secondrow = new pdfptable(3); secondrow.setkeeptogether(true); pdfpcell cell = new pdfpcell(new phrase("date 2")); cell.setrowspan(2); secondrow.addcell(cell); secondrow.addcell("event 2 1"); secondrow.addcell("more\ndetails 2 1"); secondrow.addcell("event 2 2"); secondrow.addcell("details 2 2"); document.add(headerrow); document.add(firstrow); document.add(secondrow); document.close();
honestly though, think nested table better idea.
Comments
Post a Comment