我在使用FOP将xsl和xml渲染成pdf时遇到问题。 我的表可能有很多行,我只需要一页15页 我已经尝试了几种解决方案,但很多解决方案对我来说都不起作用。 我不知道我做错了什么或只是我不知道如何处理这个问题。 如果有人能够回答我如何更改它以将其呈现为pdf中的多个页面,我将感激不尽。 这是我的第一篇文章,如果我犯了一些错误就很抱歉。
代码再次更新,它仍然无法打破 - 每个。现在它可以渲染到几个页面,但它仍然在一个页面中渲染表格,并在
下面切割所有内容 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format" >
<xsl:output method="xml" version="1.0" indent="yes" encoding="UTF-8"/>
<xsl:template match="mydata" >
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="summarypage"
page-height="11in"
page-width="8.5in"
margin-top="10mm"
margin-bottom="10mm"
margin-left="10mm"
margin-right="10mm">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="summarypage" >
<fo:flow flow-name="xsl-region-body" >
<fo:block text-align="center"
font-size="18pt"
font-weight="bold">
Number: <xsl:value-of select="title/number"/>
</fo:block>
<fo:block>
<fo:block-container position="absolute" top="100pt" left="5pt" height="40pt" width="100%">
<fo:block text-align="left"
font-size="13pt"
font-weight="bold">
Seller:
</fo:block>
</fo:block-container>
<fo:block-container position="absolute" top="100pt" left="400pt" height="40pt" width="100%">
<fo:block font-size="13pt"
font-weight="bold">
Buyer:
</fo:block>
</fo:block-container>
</fo:block>
<fo:block font-size="10pt">
<fo:block-container position="absolute" top="130pt" left="5pt"
height="40pt" width="100%">
<fo:block>
<xsl:value-of select="person/seller/name"/> </fo:block>
</fo:block-container>
<fo:block-container position="absolute" top="130pt" left="400pt"
height="40pt" width="100%">
<fo:block>
<xsl:value-of select="person/buyer/name"/> </fo:block>
</fo:block-container>
</fo:block>
<fo:block font-size="10pt">
<fo:block-container position="absolute" top="145pt" left="5pt"
height="40pt" width="100%">
<fo:block>
<xsl:value-of select="person/seller/address"/> </fo:block>
</fo:block-container>
<fo:block-container position="absolute" top="145pt" left="400pt"
height="40pt" width="100%">
<fo:block>
<xsl:value-of select="person/buyer/address"/> </fo:block>
</fo:block-container>
</fo:block>
<fo:block font-size="10pt">
<fo:block-container position="absolute" top="160pt" left="5pt"
height="40pt" width="100%">
<fo:block>
<xsl:value-of select="person/seller/land"/> </fo:block>
</fo:block-container>
<fo:block-container position="absolute" top="160pt" left="400pt"
height="40pt" width="100%">
<fo:block>
<xsl:value-of select="person/buyer/land"/> </fo:block>
</fo:block-container>
</fo:block>
<fo:block font-size="10pt">
<fo:block-container position="absolute" top="175pt" left="5pt"
height="40pt" width="100%">
<fo:block>
tel.
<xsl:value-of select="person/seller/tel"/> </fo:block>
</fo:block-container>
<fo:block-container position="absolute" top="175pt" left="400pt"
height="40pt" width="100%">
<fo:block>
tel.
<xsl:value-of select="person/buyer/tel"/> </fo:block>
</fo:block-container>
</fo:block>
<fo:block font-size="10pt">
<fo:block-container position="absolute" top="190pt" left="5pt"
height="40pt" width="100%">
<fo:block>
mail:
<xsl:value-of select="person/seller/email"/> </fo:block>
</fo:block-container>
<fo:block-container position="absolute" top="190pt" left="400pt"
height="40pt" width="100%">
<fo:block>
mail:
<xsl:value-of select="person/buyer/email"/> </fo:block>
</fo:block-container>
</fo:block>
<fo:block-container top="100pt" left="0pt" height="40pt" width="100%" text-align="center" table-layout="fixed" margin-top="200pt" margin-bottom="100pt">
<fo:table border-collapse="collapse" font-size="12pt" font-family="Arial">
<fo:table-column column-width="7mm" column-number="1"/>
<fo:table-column column-width="60mm" column-number="2"/>
<fo:table-column column-width="15mm" column-number="3"/>
<fo:table-column column-width="10mm" column-number="4"/>
<fo:table-column column-width="19mm" column-number="5"/>
<fo:table-column column-width="30mm" column-number="6"/>
<fo:table-column column-width="16mm" column-number="7"/>
<fo:table-column column-width="22mm" column-number="8"/>
<fo:table-column column-width="16mm" column-number="9"/>
<fo:table-header font-weight="bold">
<fo:table-row>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block> Nr. </fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>Service</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>j.m </fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>Amount </fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>netto_price_per_amount</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>netto_value"</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>VAT_Percent</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>VAT_tax</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block>brutto_value</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body >
<xsl:for-each select="items/item" >
<fo:table-row >
<xsl:if test="position() > 15 and position() mod 15 = 1">
<xsl:attribute name="break-before">page</xsl:attribute>
</xsl:if>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:number/>.</fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:value-of select="service" /></fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:value-of select="jm" /></fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:value-of select="amount" /></fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:value-of select="netto_price_per_amount" /></fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:value-of select="netto_value" /></fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:value-of select="VAT_Percent" /></fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block><xsl:value-of select="VAT_tax" /></fo:block>
</fo:table-cell>
<fo:table-cell padding="2pt" border="1pt solid black">
<fo:block ><xsl:value-of select="brutto_value" /></fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block-container>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
您的桌子放在绝对定位的块容器内:
<fo:block-container position="absolute" top="250pt" left="0"
height="40pt" width="100%" text-align="center" >
...
它只会在放置的页面上呈现。
答案 1 :(得分:0)
您是否尝试过以下操作?
<xsl:if test="position() mod 15 = 1">
<xsl:attribute name="break-before">page</xsl:attribute>
</xsl:if>
如果表格的第一行不在页面顶部,那么您需要这样做:
<xsl:if test="position() > 15 and position() mod 15 = 1">
<xsl:attribute name="break-before">page</xsl:attribute>
</xsl:if>
这将在您的<fo:table-row>
开始标记之后。