xslt - xsl fo 页面大小/方向

标签 xslt pdf-generation xsl-fo documents

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

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

您好 mzjn,我没有任何链接。附上预期和结果的 pdf 输出,resulted pdf - rotated clockwise expected还需要知道如何使用边框图像。尝试作为区域主体的背景图像但失败。

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

附上代码示例

最佳答案

我正在使用 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>

谢谢。

关于xslt - xsl fo 页面大小/方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14382603/

相关文章:

javascript - 在 XSL 转换期间在字符串中保留注释符号

xslt - XSL-FO- 指定条件可见性

XSLT 键()查找

xml - 组合 <xsl :param> and <xsl:include>

c# - 使用 Aspose.Pdf 库制作 1 层 pdf

python - pdfkit 没有在网页中获取嵌入图像

c# - 哪些软件可用于创建服务器端 PDF 文件?

xslt - 如何在不扩大行高的情况下在段落的第一行生成首字母?

static - xsl-fo header - 左侧图像,右侧三行文本,顶部对齐

xml - 快速将 XML 转换为 Excel