1
votes

I have a list of objects that I want to iterate over using Freemarker to produce a FOP template that shows four of these items on each page.

Each item should take up a quarter of the page.

In HTML I would probably float the divs so they flow together as they fit the page, but I don't know how to do that with FOP.

I've tried using inline elements to achieve this, but that doesn't work as I expect.

      <fo:page-sequence master-reference="apage">
    <fo:flow flow-name="xsl-region-body">
        <fo:block>
          <#list entries as entry>
            <fo:inline background-color="blue" border="2px solid black">
                <fo:block height="100mm" width="150mm"  background-color="red" border="2px solid green">
                    <#include "singleCardTemplate.ftl">
                </fo:block>
            </fo:inline>
          </#list>
      </fo:block>
    </fo:flow>
  </fo:page-sequence>

The singleCardTemplate.ftl included is responsible for rendering a single item, which seems to be working, only it renders at full width, not 150mm as I'd hoped. I'd like 2x150mm wide blocks next to each other with 2 more underneath. So four per page.

I'm happy the Freemarker/FOP combo is working properly, I do get a PDF generated with the correct content and some borders/colours as per above.

What am I doing wrong?

1

1 Answers

0
votes

I found a solution, move to table layout. I'd prefer to use a layout that flowed like HTML inline-block elements but this seems to work...

    <fo:flow flow-name="xsl-region-body">
        <fo:block>
            <fo:table table-layout="fixed" height="100%">
                 <fo:table-column  column-width="proportional-column-width(2)"/>
                 <fo:table-column  column-width="proportional-column-width(2)"/>
                 <fo:table-body font-size="10pt">
                    <fo:table-row height="100mm">
                        <#list entries as entry>
                            <fo:table-cell margin="5mm">
                                <#include "singleCardTemplate.ftl">
                            </fo:table-cell>
                            <#assign mod = entry_index % 2 />
                            <#if entry_has_next>
                                <#if mod == 0>
                                    </fo:table-row>
                                    <fo:table-row  height="100mm">
                                </#if>
                            </#if>
                        </#list>
                    </fo:table-row>
                 </fo:table-body>
            </fo:table>
        </fo:block>
    </fo:flow>