FOP pdf generation : display table side by side based on its content

47 Views Asked by At

I want to display tables side by side based on content of table cell. If contents of cell is using more than 50% of page width than next table should be displayed below that table.

To create pdf from xml in Java, I am using Apache XML graphics 2.7 library.

1

There are 1 best solutions below

0
Tony Graham On

FOP does not do automatic table layout (https://www.w3.org/TR/xsl11/#table-layout, https://xmlgraphics.apache.org/fop/compliance.html#fo-object-table), so it requires that you specify the column widths/proportions in your XSL-FO. As such, you can't have a table is unexpectedly wider than 50% of the page width because you've had to determine the table width in advance (unless, that is, different pages have different widths).

Also because of no automatic table layout, if you want to do a first pass to work out the widths of the tables, you probably need to make a throwaway document where every table column becomes a separate one-column table with a specified width (the maximum that you want to allow for that column in the final document). You would then format that document, look at its area tree (FOP has two forms of area tree markup), find the maximum used width of the content of the cells in each column, then generate your real XSL-FO using column widths that you calculated.

All of this is somewhat easier with automatic table layout.


If you have your table widths already but don't know which sorts of tables will be next to each other, you could put each table in an fo:inline-container, and FOP should take care of putting the second fo:inline-container on the next line if it would otherwise overflow.

The fo:block containing the fo:inline-container would want line-stacking-strategy="max-height" so that the tables clear each other. I haven't looked into whether FOP can do alignment baselines so that side-by-side tables would have their tops aligned.