如何使用FOP在XSL-FO中保留带有标题的表,但允许在表主体内部进行分页 [英] how to keep table with header but allow page breaks inside table body in XSL-FO using FOP

查看:69
本文介绍了如何使用FOP在XSL-FO中保留带有标题的表,但允许在表主体内部进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache FOP和XSL-FO样式表生成PDF.在PDF中,我输出属于一个表的标题(html equiv h1),因此应始终保持在一起.但是,我的表可能还包含太多数据,因此它们不一定适合一页.

I'm generating a PDF using Apache FOP and a XSL-FO stylesheet. In the PDF, I output headings (html equiv h1) which belong to a table, so should be kept together always. However, my tables may also contain so much data that they don't necessarily fit on one page.

期望的结果是一个规则集,该标题集允许表保留标题,并在可能的情况下将其全部容纳在一页上,但是如果表数据太长而不能容纳在一页上,则分页符将插入表格中,同时仍将标题元素与表格的开头放在同一页面上.

The desired result is a rule set that allows a heading to be kept with the table and fit both on one page if possible, but if the table data is so long that it does not fit on one page, then page breaks would be inserted in the table while still keeping the heading element on the same page as the start of the table.

我现在拥有的解决方案确实将标题和表格保持在一起,但是如果所有内容都不适合一页,则会出现表格数据的内容溢出错误.我希望page-break-inside:避免在table元素上设置会对此有所帮助,但显然不是...建议?

The solution I have right now does keep the heading and the table together, but I get an Content overflows error for the table data if everything does not fit onto one page. I was hoping that page-break-inside: avoid set on the table element would help with this, but apparently not... suggestions?

xsl示例(出于可读性的考虑而缩短):

Example xsl (cut short for readability):

<!-- add test table with header that should stay on same page -->
<fo:block font-size="20pt" font-weight="bold">Table header</fo:block>

<fo:table keep-with-previous.within-page="always"
      page-break-inside="avoid" 
      table-layout="fixed" border-width="1mm" border-style="solid">
  <fo:table-column column-width="auto" />
  <fo:table-column column-width="30mm" />

  <fo:table-header text-align="center" background-color="silver">
    <fo:table-row>
      <fo:table-cell padding="1mm" border-width="1mm" border-style="solid">
    <fo:block>First name</fo:block>
      </fo:table-cell>
      <fo:table-cell padding="1mm" border-width="1mm" border-style="solid">
    <fo:block>Last name</fo:block>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-header>
  <fo:table-body>
    <!-- the table-rows can be repeated N times, spanning several pages -->
    <fo:table-row >
      <fo:table-cell padding="1mm" border-width="1mm" border-style="solid">
    <fo:block>ab</fo:block>
      </fo:table-cell>
      <fo:table-cell padding="1mm" border-width="1mm" border-style="solid">
    <fo:block>cd</fo:block>
      </fo:table-cell>
    </fo:table-row>
    <!-- .... more table-row:s ---> 

更新所需的输出

为了更好地描述我正在寻找什么结果:

Update on desired output

To better describe what result I'm looking for:

结果文档包含文本段落,标题和表格.

The result document contains both text paragraphs, headings and tables.

  1. 如果内容的数量足以使该表在下一页上只有一行或两行,那么xsl-fo应该将整个表和标题移到下一页,前提是它完全适合该页面.
  2. 另一方面,如果表中的行太多,以至于无论如何它都无法容纳在一个全新的页面上,那么应该立即在文档流中开始输出,同时仍然允许将表拆分成几页.

如果我删除page-break-inside ="avoid",那么我得到的表可以很好地跨越多个页面,但是#1中描述的情况将不匹配. IE.它不会移动表,并且如果只有几行最终将移至下一页,则它将完全移至下一页.如果我不进行分页,那么长表就会出现内容溢出问题,因为页面上不适合的行不会移到下一页.

If I remove page-break-inside="avoid", then I get a table that breaks across several pages nicely, but cases described in #1 would not be matched. I.e. it does not move a table and it's heading entirely to the next page if only a few rows would end up being moved to the next page. If I leave page-break-inside, then I get a content overflow problem with long tables, because rows that don't fit on the page are not moved to the next page.

我猜这是一个基本问题,我的输出表的长度非常动态,不幸的是,我对表中产生的数据量没有任何控制.

I guess one of the basic problems is that my output tables are very dynamic in length and unfortunately I don't have any control over what amount of data gets produced into the tables.

推荐答案

CSS属性 page-break -inside ="avoid" 映射到本地FO属性keep-together ="always".这种映射是可疑的海事组织(但这是另一回事).无论如何,我建议您使用本机FO属性 keep-together.within-column ="1" 而不是分页入内.这使得Apache FOP在绝对必要时可以在表内中断.

The CSS property page-break-inside="avoid" maps to the native FO property keep-together="always". This mapping is questionable IMO (but that's a different story). Anyway, I suggest you use the native FO property keep-together.within-column="1" instead of page-break-inside. That allows Apache FOP to break inside the table when absolutely necessary.

这篇关于如何使用FOP在XSL-FO中保留带有标题的表,但允许在表主体内部进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆