我正在使用xsl-fo将大量文本加载到PDF中。但是,当它加载时,它将整个页面从边框填充到边框。是否有一种方法可以防止文本越过之前,之后,开始和结束块,或者我应该在包含文本的块上设置边距?
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<fo:root>
<!-- overall layout -->
<fo:layout-master-set>
<fo:simple-page-master master-name="forSalePage">
<fo:region-body/>
<fo:region-before extent="1in" background-color="#0000FF" />
<fo:region-after extent="1in" background-color="#0000FF" />
<fo:region-start/>
<fo:region-end/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- page content -->
<xsl:for-each select="ovgs/forSale/game">
<fo:page-sequence master-reference="forSalePage">
<fo:flow flow-name="xsl-region-body">
<fo:block text-align="center" margin-top="0.1in">Pros:</fo:block>
<xsl:for-each select="review/pros/pro">
<fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
</xsl:for-each>
<fo:block text-align="center" margin-top="0.1in">Cons:</fo:block>
<xsl:for-each select="review/cons/con">
<fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
</xsl:for-each>
<fo:block page-break-before="always" margin-top="1.1in" margin-right="1in" margin-left="1in">Content:</fo:block>
<xsl:for-each select="review/content/*">
<xsl:choose>
<xsl:when test=". = not(node())">
<fo:block margin-top="0.1in" margin-right="1in" margin-left="1in"><xsl:value-of select="./preceding::text()[1]" /></fo:block>
</xsl:when>
<xsl:when test=". = text()">
<fo:block text-align="center" margin-top="0.1in"><fo:external-graphic content-height="scale-to-fit" height="1in"><xsl:attribute name="src">url('<xsl:value-of select="./@url" />')</xsl:attribute></fo:external-graphic></fo:block>
<fo:block text-align="center" margin-right="1in" margin-left="1in"><xsl:value-of select="." /></fo:block>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:for-each>
<fo:block margin-right="1in" margin-left="1in" margin-top="0.1in"><xsl:value-of select="review/content/p[last()]/following::text()[1]" /></fo:block>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>
这是显示xml文件的Pros、Cons和Review内容的代码。它正确地显示所有信息和图片,并在必要时在Cons后面插入分页符。但问题是,评论内容太多了,只需要一个页面,并显示在前后区域。
What I get: What I want:
______________ ______________
| | | |
| Pros | | Pros |
| Blabla | | Blabla |
| | | |
| Cons | | Cons |
| Blabla | | Blabla |
| | | |
| | | |
|______________| |______________|
______________ ______________
| | | |
| Content | | Content |
| | | |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
|__~~~~~~~~~~__| |______________|
______________ ______________
| ~~~~~~~~~~ | | |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
| ~~~~~~~~~~ | | ~~~~~~~~~~ |
| | | ~~~~~~~~~~ |
| | | ~~~~~~~~~~ |
| | | |
| | | |
|______________| |______________|
以下是区域及其名称:
______________
| Before |
|______________|
| S| | |
| t| |E |
| a| Body |n |
| r| |d |
| t| | |
|__|________|__|
| After |
|______________|
(注:正文延伸到页面边框,而不只是延伸到其他区域)
你似乎错过了两件事:
首先,页面的宽度和高度,将<fo:simple-page-master master-name="forSalePage">
改为<fo:simple-page-master master-name="forSalePage" page-height="11in" page-width="8.5in">
<fo:region-body/>
改为<fo:region-body margin="1in"/>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<fo:root>
<!-- overall layout -->
<fo:layout-master-set>
<fo:simple-page-master master-name="forSalePage">
<fo:region-body margin="1in" />
<fo:region-before extent="1in" background-color="#0000FF" />
<fo:region-after extent="1in" background-color="#0000FF" />
<fo:region-start/>
<fo:region-end/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- page content -->
<xsl:for-each select="ovgs/forSale/game">
<fo:page-sequence master-reference="forSalePage">
<fo:flow flow-name="xsl-region-body">
<fo:block text-align="center" margin-top="0.1in">Pros:</fo:block>
<xsl:for-each select="review/pros/pro">
<fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
</xsl:for-each>
<fo:block text-align="center" margin-top="0.1in">Cons:</fo:block>
<xsl:for-each select="review/cons/con">
<fo:block text-align="center">-<xsl:value-of select="." /></fo:block>
</xsl:for-each>
<fo:block page-break-before="always" margin-top="0.1in">Content:</fo:block>
<xsl:for-each select="review/content/*">
<xsl:choose>
<xsl:when test=". = not(node())">
<fo:block margin-top="0.1in"><xsl:value-of select="./preceding::text()[1]" /></fo:block>
</xsl:when>
<xsl:when test=". = text()">
<fo:block text-align="center" margin-top="0.1in"><fo:external-graphic content-height="scale-to-fit" height="1in"><xsl:attribute name="src">url('<xsl:value-of select="./@url" />')</xsl:attribute></fo:external-graphic></fo:block>
<fo:block text-align="center"><xsl:value-of select="." /></fo:block>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:for-each>
<fo:block margin-top="0.1in"><xsl:value-of select="review/content/p[last()]/following::text()[1]" /></fo:block>
</fo:flow>
</fo:page-sequence>
</xsl:for-each>
</fo:root>
</xsl:template>