2013-05-21 44 views
2

我使用xsl-fo將文本的分配加載到PDF中。但是當它加載時,它完全從邊框到邊框填充頁面。有沒有辦法阻止文本能夠覆蓋之前,之後,開始和結束塊,還是應該只在包含我的文本的塊上放置邊距?如何防止文本使用xsl-fo覆蓋之前和之後的區域?

<?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文件的優缺點和評論內容。它正確顯示所有信息和圖片,並在缺陷之後插入分頁符。但是問題出現在評論內容對於一個頁面而言太多並且顯示在之後和之前的區域上。

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

(PS身體一直延伸到頁面邊框,而不僅僅是其他地區)

+0

改變<fo:region-body/>請分享您生成的PDF片段和XSL-FO瞭解清楚。 –

+0

這就是你想看到的嗎? – wizzkid

+1

看起來你錯過了兩件事: 首先,頁面的寬度和高度,用 第二,用更改

回答

4

看來你錯過了兩件事情在這裏:

首先,頁面的寬度和高度,更改<fo:simple-page-master master-name="forSalePage"><fo:simple-page-master master-name="forSalePage" page-height="11in" page-width="8.5in">

其次,<fo:region-body margin="1in"/>

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