3

我正在设计一个将提供 pdf 输出的 xsl。我的 pdf 输出是横向格式。即使我按如下方式更改简单的页面主文件,我也无法获得横向格式的输出,

我的 pdf 输出的高度仍然大于宽度。

嗨 mzjn,我没有任何链接。附上预期和结果的 pdf 输出,结果 pdf - 顺时针旋转 预期的还需要知道如何使用边框图像。尝试作为区域主体的背景图像并失败。

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

附上代码示例

4

2 回答 2

3

我正在使用 Apache FOP 1.1。首先你应该定义景观布局(A2)。例如

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

谢谢你。

于 2013-10-07T11:33:22.223 回答
1

我不确定如何设置背景,但下面是我如何能够更改页面宽度和高度以形成横向。

我正在为 DITA 开放工具包附带的 PDF2 编辑 xsl 文件。我不确定文件名是否相同,但我在 layout-masters-attr.xsl 中找到了以下代码块。请注意,我切换了 page-width 和 page-height 变量。

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

这会将整个 PDF 文档设置为横向模式。此外,如果需要,您可以找到变量的定义位置并将它们更改为其他值。

于 2013-08-20T22:11:15.407 回答