Pregunta

I'm loading allot of text into a PDF using xsl-fo. But when it loads it fills the page entirely from border to border. Is there a way to prevent the text from being able to go over the before, after, start and end blocks, or should I just put margins on the blocks containing my text?

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

That is the code to display the Pros, Cons and Review content of the xml file. It displays all the information and pictures correctly and inserts a page break after the Cons as it must. But the problem comes in where the Review content is too much for just one page and displays over the after- and before-regions.

What I get:           What I want:
 ______________       ______________
|              |     |              |
|  Pros        |     |  Pros        |
|    Blabla    |     |    Blabla    |
|              |     |              |
|  Cons        |     |  Cons        |
|    Blabla    |     |    Blabla    |
|              |     |              |
|              |     |              |
|______________|     |______________|
 ______________       ______________
|              |     |              |
|  Content     |     |  Content     |
|              |     |              |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|__~~~~~~~~~~__|     |______________|
 ______________       ______________
|  ~~~~~~~~~~  |     |              |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|  ~~~~~~~~~~  |     |  ~~~~~~~~~~  |
|              |     |  ~~~~~~~~~~  |
|              |     |  ~~~~~~~~~~  |
|              |     |              |
|              |     |              |
|______________|     |______________|

Here is the regions and their names:

 ______________
|    Before    |
|______________|
| S|        |  |
| t|        |E |
| a|  Body  |n |
| r|        |d |
| t|        |  |
|__|________|__|
|    After     |
|______________|

(P.S. the body stretches to the page border and not just to the other regions)

¿Fue útil?

Solución

It seems you missed two things here:

First, width and height of page, change <fo:simple-page-master master-name="forSalePage"> with <fo:simple-page-master master-name="forSalePage" page-height="11in" page-width="8.5in">

Second, change <fo:region-body/> with <fo:region-body margin="1in"/>

Otros consejos

<?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>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top