【问题标题】:How can I render a list of items as 4 blocks using Freemarker and Apache FOP?如何使用 Freemarker 和 Apache FOP 将项目列表呈现为 4 个块?
【发布时间】:2014-07-13 10:38:48
【问题描述】:

我有一个对象列表,我想使用 Freemarker 迭代生成一个 FOP 模板,该模板在每个页面上显示其中四个项目。

每个项目应占页面的四分之一。

在 HTML 中,我可能会浮动 div,以便它们在适合页面时一起流动,但我不知道如何使用 FOP 来做到这一点。

我已经尝试使用内联元素来实现这一点,但这并不符合我的预期。

      <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>

包含的 singleCardTemplate.ftl 负责渲染单个项目,这似乎可以正常工作,只是它以全宽渲染,而不是我希望的 150 毫米。我想要 2x150mm 宽的块彼此相邻,下面还有 2 个。所以每页四个。

我很高兴 Freemarker/FOP 组合工作正常,我确实得到了一个 PDF,其中包含正确的内容和上面的一些边框/颜色。

我做错了什么?

【问题讨论】:

    标签: freemarker apache-fop


    【解决方案1】:

    我找到了解决方案,转到表格布局。 我更喜欢使用像 HTML inline-block 元素一样流动的布局,但这似乎工作......

        <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>
    

    【讨论】:

      猜你喜欢
      • 2014-06-08
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2019-07-20
      • 2021-08-05
      • 2022-12-29
      • 1970-01-01
      • 2018-01-14
      相关资源
      最近更新 更多