lourdh
lourdh

Reputation: 459

xsl fo page size / orientation

I am designing an xsl that will give a pdf output. My pdf output is in landscape format. I can't get the landscape formatted output even i change the simple page master as follows,

Still my pdf output's height is greater than the width.

Hi mzjn, i dont have any link. attached the expected and resulted pdf outputs, resulted pdf - rotated clockwise expectedalso need to know how to use the border image. tried as background image for region body and failed.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="fo">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no"
    indent="yes" />
<xsl:param name="versionParam" select="'1.0'" />
<xsl:template match="@*|node()">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <!-- Start of page layout -->
        <fo:layout-master-set>
            <fo:simple-page-master master-name="A4"
                page-width="8.27in" page-height="11.69in" margin-top="5mm"
                margin-bottom="5mm" margin-left="5mm" margin-right="5mm"
                reference-orientation="90">
                <fo:region-body margin-top=".5cm" margin-bottom=".5cm"
                    margin-left=".5cm" margin-right=".5cm">
                    <xsl:if test="isPreview='true'">
                        <xsl:attribute name="background-image">file:///<xsl:value-of
                            select="pdfimagepath" />Preview Only1.JPG</xsl:attribute>
                    </xsl:if>
                </fo:region-body>
                <fo:region-before extent="0mm" />
                <fo:region-after extent="0mm" />

            </fo:simple-page-master>
        </fo:layout-master-set>
        <!-- End of page layout -->

        <fo:page-sequence master-reference="A4">
            <fo:static-content flow-name="xsl-region-before">
                <fo:block>
                    <fo:leader></fo:leader>
                </fo:block>
                <fo:block text-align="right" font-size="9pt" font-weight="bold">
                    <xsl:value-of select="num" />
                </fo:block>
            </fo:static-content>
            <fo:static-content flow-name="xsl-region-after">
                <fo:block font-size="9pt" font-family="times" text-align="left">

                    <xsl:value-of select="xxx" />
                </fo:block>
            </fo:static-content>

            <fo:flow flow-name="xsl-region-body">
                <fo:block>
                    <fo:table table-layout="fixed" width="100%">
                        <fo:table-header>
                            <fo:table-row>
                                <fo:table-cell>
                                    <fo:block></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-header>
                        <fo:table-body>
                            <fo:table-row>
                                <fo:table-cell width="100%">
                                    <fo:block text-align="center" padding-top="2pt">
                                        <fo:external-graphic content-height="85%"
                                            content-width="65%" scaling="uniform">
                                            <xsl:attribute name="src">
                                <xsl:value-of select="pdfimagepath" />LogoCert.jpg
                                </xsl:attribute>
                                        </fo:external-graphic>
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell width="100%">
                                    <fo:block text-align="center">
                                        <fo:external-graphic content-height="45%"
                                            content-width="55%" scaling="non-uniform">
                                            <xsl:attribute name="src">
                                    <xsl:value-of select="pdfimagepath" />title.jpg
                                    </xsl:attribute>
                                        </fo:external-graphic>
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell width="100%">
                                    <fo:block font-size="15.5pt" font-family="Arial"
                                        color="Black" text-align="center" padding-before="5pt"
                                        start-indent="10pt">
                        </fo:block>
                                    <fo:block font-size="15.5pt" font-family="Arial"
                                        color="Black" text-align="center" start-indent="5pt">xxxxxx:
                        </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell width="100%">
                                    <fo:block font-size="16.5pt" font-family="Arial"
                                        color="red" text-align="center" padding-before="8pt">
                                        <xsl:value-of select="custname" />

                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell width="100%">
                                    <fo:block font-size="13.5pt" font-family="Arial"
                                        color="black" text-align="center" padding-before="10pt"
                                        start-indent="10pt">
                                        <fo:inline background-color="yellow">xxxx</fo:inline>xxxx
                                    </fo:block>
                                    <fo:block font-size="13.5pt" font-family="Arial"
                                        color="black" text-align="center" start-indent="10pt"> xxxx
                        </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell padding-start="140pt" padding-end="140pt">
                                    <fo:block font-size="10pt" font-family="Arial" color="black"
                                        text-align="center" border-bottom="solid">
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell display-align="after"
                                    padding-after="12pt" padding-before="2pt">
                                    <fo:block font-size="15.5pt" font-family="Arial"
                                        color="black" text-align="center"> xxxx
                        </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell padding-start="160pt" padding-end="160pt">
                                    <fo:block font-size="10pt" font-family="Arial" color="black"
                                        text-align="center" border-bottom="solid">
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>

                            <fo:table-row>
                                <fo:table-cell padding-before="2pt"
                                    display-align="before">
                                    <fo:block font-size="15.5pt" font-family="Arial"
                                        color="black" text-align="center"> 
                                                </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell padding-before="10pt">
                                    <fo:block font-size="8.5pt" font-family="Arial"
                                        color="black" text-align="center"> xxxx
                                                </fo:block>
                                    <fo:block font-size="8.5pt" font-family="Arial"
                                        color="black" text-align="center">
                                                </fo:block>
                                    <fo:block font-size="8.5pt" font-family="Arial"
                                        color="black" text-align="center"> 
                                                </fo:block>
                                    <fo:block font-size="8.5pt" font-family="Arial"
                                        color="black" text-align="center"> 
                                                </fo:block>
                                    <fo:block font-size="8.5pt" font-family="Arial"
                                        color="black" text-align="center">
                                                </fo:block>
                                    <fo:block font-size="8.5pt" font-family="Arial"
                                        color="black" text-align="center"> 
                                                </fo:block>
                                </fo:table-cell>
                            </fo:table-row>

                            <fo:table-row>
                                <fo:table-cell padding-before="5pt"
                                    padding-start="60pt" padding-end="60pt">
                                    <fo:block font-size="20pt" font-family="Arial" color="black"
                                        text-align="center" border-bottom="solid">
                                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-body>
                    </fo:table>
                    <fo:table table-layout="fixed" width="100%">
                        <fo:table-column column-width="40%" />
                        <fo:table-column column-width="60%" />
                        <fo:table-header>
                            <fo:table-row>
                                <fo:table-cell>
                                    <fo:block></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-header>
                        <fo:table-body>
                            <fo:table-row>
                                <fo:table-cell padding-before="5pt">
                                    <fo:block font-size="9.5pt" text-align="left"
                                        font-weight="normal">
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding-before="5pt">
                                    <fo:block font-size="9.5pt" text-align="center"> 
                                    </fo:block>
                                    <fo:block font-size="9.5pt" text-align="center"
                                        end-indent="10pt"> 
                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-body>
                    </fo:table>
                    <fo:table table-layout="fixed" width="100%">
                        <fo:table-column column-width="50%" />
                        <fo:table-column column-width="50%" />
                        <fo:table-header>
                            <fo:table-row>
                                <fo:table-cell>
                                    <fo:block></fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-header>
                        <fo:table-body>
                            <fo:table-row>
                                <fo:table-cell padding-before="5pt"
                                    display-align="after" border="">
                                    <fo:block font-size="10pt" text-align="left"
                                        font-weight="normal">
                                    </fo:block>
                                    <fo:block font-size="13.5pt" text-align="center"
                                        font-weight="normal"> 
                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell padding-before="5pt"
                                    display-align="after" border="">
                                    <fo:block text-align="center">
                                        <fo:external-graphic content-height="60%"
                                            content-width="40%" scaling="uniform">
                                            <xsl:attribute name="src">
                                <xsl:value-of select="pdfimagepath" />sign.jpg
                                </xsl:attribute>
                                        </fo:external-graphic>
                                    </fo:block>
                                    <fo:block padding-bottom="1pt" font-size="15pt"
                                        text-align="center" font-weight="bold">
                                        _____________________________
                    </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                            <fo:table-row>
                                <fo:table-cell display-align="after" border="">
                                    <fo:block font-size="8pt" text-align="left"
                                        font-weight="normal">
                                    </fo:block>
                                </fo:table-cell>
                                <fo:table-cell display-align="after" border=""
                                    padding-before="1pt">
                                    <fo:block font-size="8.5pt" text-align="center"
                                        font-weight="normal">xxxxx
                                </fo:block>
                                    <fo:block font-size="8.5pt" text-align="center"
                                        font-weight="normal">yyyyy
                                </fo:block>
                                </fo:table-cell>
                            </fo:table-row>
                        </fo:table-body>
                    </fo:table>
                </fo:block>
            </fo:flow>
        </fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

code sample attached

Upvotes: 3

Views: 11148

Answers (2)

Oomph Fortuity
Oomph Fortuity

Reputation: 6178

I am using Apache FOP 1.1.First you should define layout of landscape(A2).For Example

<fo:layout-master-set>
        <fo:simple-page-master master-name="A2"
                    page-height="594mm" page-width="420mm" margin-left="0.2cm"
                    margin-right="0.2cm">
        <fo:region-body margin-top="0.5cm" />
                </fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A2">
                <fo:flow flow-name="xsl-region-body">

                 **//your design and logic**

                            </fo:flow>
</fo:page-sequence>

Thank you.

Upvotes: 3

Noah
Noah

Reputation: 582

I'm not sure how to set the background, but below is how I was able to change the page width and height to result in landscape orientation.

I'm editing xsl files for PDF2 that came with the DITA open toolkit. I'm not sure if the filename will be the same, but I found the below chunk of code in layout-masters-attr.xsl. Notice I switched the page-width and page-height variables.

<xsl-attribute-set name="simple-page-master">
    <xsl-attribute name="page-width">
        <xsl:value-of select="$page-height"/>
    </xsl:attribute>
    <xsl:attribute name="page-height">
        <xsl:value-of select="$page-width"/>
    </xsl:attribute>
</xsl:attribute-set>

This will set the entire PDF document to landscape mode. Also, you can find where the variables are defined and change them to other values, if desired.

Upvotes: 1

Related Questions