打印pdf时XSL-FO格式关闭,但xsl-fo代码显示正常吗?软件:XML2PDF

时间:2014-08-10 17:35:02

标签: xslt xsl-fo

我正在使用XML2PDF来创建打印徽章。不幸的是,我遇到了一个问题,当创建一个新页面(page-break-after =“always”)时,下一个块容器是重复的。当块容器具有指定高度时,似乎会发生这种情况。没有height属性,数据看起来没问题(虽然我需要指定高度)。

我还注意到,在simple-page-master中增加页面高度也可以解决这个问题。我不确定为什么因为块容器和边距不超过11​​英寸高度。

非常感谢任何帮助。如果我遗漏了任何信息,请告诉我

注意:

每页有6个徽章。 2列3行。 (每个徽章的宽度为4英寸,高度为3英寸)

每页的页脚宽度为4英寸,高度为1.5英寸

  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
     <fo:simple-page-master master-name="badge" page-width="8.5in" page-height="11in" margin-top="0.00in" margin-bottom="0.00in" margin-left="0.00in" margin-right="0.00in">
        <fo:region-body margin=".25in"/>
        <fo:region-before extent="0in"/>
        <fo:region-after extent="0in"/>
        <fo:region-start extent="0in"/>
        <fo:region-end extent="0in"/>
    </fo:simple-page-master>
</fo:layout-master-set>
 <fo:page-sequence master-reference="badge">
     <fo:flow flow-name="xsl-region-body">
         <fo:float float="left">
             <fo:block-container background-color="gray" height="3in" width="4in">
                <fo:block font-size="34px" font-weight="bold">Name - 1</fo:block>
                <fo:block font-size="18px">Full Name</fo:block>
                <fo:block font-size="18px">Company</fo:block>
                <fo:block font-size="18px">City, State</fo:block>
            </fo:block-container>
        </fo:float>
         <fo:float float="left">
             <fo:block-container background-color="gray" height="3in" width="4in">
                <fo:block font-size="34px" font-weight="bold">Name - 2</fo:block>
                <fo:block font-size="18px">Full Name</fo:block>
                <fo:block font-size="18px">Company</fo:block>
                <fo:block font-size="18px">City, State</fo:block>
            </fo:block-container>
        </fo:float>
        <fo:float clear="left"/>
         <fo:float float="left">
             <fo:block-container background-color="gray" height="3in" width="4in">
                <fo:block font-size="34px" font-weight="bold">Name - 3</fo:block>
                <fo:block font-size="18px">FullName</fo:block>
                <fo:block font-size="18px">Company</fo:block>
                <fo:block font-size="18px">City, State</fo:block>
            </fo:block-container>
        </fo:float>
         <fo:float float="left">
             <fo:block-container background-color="gray" height="3in" width="4in">
                <fo:block font-size="34px" font-weight="bold">Name - 4</fo:block>
                <fo:block font-size="18px">Full Name</fo:block>
                <fo:block font-size="18px">Company</fo:block>
                <fo:block font-size="18px">City, State</fo:block>
            </fo:block-container>
        </fo:float>
        <fo:float clear="left"/>
         <fo:float float="left">
             <fo:block-container background-color="gray" height="3in" width="4in">
                <fo:block font-size="34px" font-weight="bold">Name - 5</fo:block>
                <fo:block font-size="18px">Full Name </fo:block>
                <fo:block font-size="18px">Company</fo:block>
                <fo:block font-size="18px">City, State</fo:block>
            </fo:block-container>
        </fo:float>
         <fo:float float="left">
             <fo:block-container background-color="gray" height="3in" width="4in">
                <fo:block font-size="34px" font-weight="bold">Name - 6</fo:block>
                <fo:block font-size="18px">Full Name</fo:block>
                <fo:block font-size="18px"/>
                <fo:block font-size="18px">City, State</fo:block>
            </fo:block-container>
        </fo:float>
        <fo:float clear="left"/>
         <fo:block-container background-color="gray" height="1.5in" width="8in" page-break-after="always">
            <fo:block> Text goes here </fo:block>
        </fo:block-container>
         <fo:float float="left">
             <fo:block-container background-color="gray" height="3in" width="4in">
                <fo:block font-size="34px" font-weight="bold">Name - 7</fo:block>
                <fo:block font-size="18px">Full Name</fo:block>
                <fo:block font-size="18px">Company</fo:block>
                <fo:block font-size="18px">City, State</fo:block>
            </fo:block-container>
        </fo:float>
    </fo:flow>
</fo:page-sequence>

1 个答案:

答案 0 :(得分:1)

我相信我理解你的问题,你是说带有“Text goes here”的块容器被抛到下一页?当你“想”所有间距加起来时,你会想到一件事。抛出fo:float时,它具有基于默认字体的固有行高。如果你想要它完全适合,你需要在浮动上将行高设置为“0”,然后在块容器内部将其设置回正常。您的文件实际上是第一个块的行高。这格式化为两页(注意我还删除了空的fo:float元素,从技术上讲,这是格式化程序的一个错误,因为float不能为空而且不需要它们。)

(仅使用RenderX的格式化程序测试,我没有XML2PDF):

    <fo:page-sequence master-reference="badge">
        <fo:flow flow-name="xsl-region-body">

            <fo:float float="left" line-height="0">
                <fo:block-container background-color="gray" height="3in" width="4in" line-height="normal">
                    <fo:block font-size="34px" font-weight="bold">Name - 1</fo:block>
                    <fo:block font-size="18px">Full Name</fo:block>
                    <fo:block font-size="18px">Company</fo:block>
                    <fo:block font-size="18px">City, State</fo:block>
                </fo:block-container>
            </fo:float>
            <fo:float float="left" line-height="0">
                <fo:block-container background-color="gray" height="3in" width="4in" line-height="normal">
                    <fo:block font-size="34px" font-weight="bold">Name - 2</fo:block>
                    <fo:block font-size="18px">Full Name</fo:block>
                    <fo:block font-size="18px">Company</fo:block>
                    <fo:block font-size="18px">City, State</fo:block>
                </fo:block-container>
            </fo:float>
            <fo:float float="left" line-height="0">
                <fo:block-container background-color="gray" height="3in" width="4in" line-height="normal">
                    <fo:block font-size="34px" font-weight="bold">Name - 3</fo:block>
                    <fo:block font-size="18px">FullName</fo:block>
                    <fo:block font-size="18px">Company</fo:block>
                    <fo:block font-size="18px">City, State</fo:block>
                </fo:block-container>
            </fo:float>
            <fo:float float="left" line-height="0">
                <fo:block-container background-color="gray" height="3in" width="4in" line-height="normal">
                    <fo:block font-size="34px" font-weight="bold">Name - 4</fo:block>
                    <fo:block font-size="18px">Full Name</fo:block>
                    <fo:block font-size="18px">Company</fo:block>
                    <fo:block font-size="18px">City, State</fo:block>
                </fo:block-container>
            </fo:float>
            <fo:float float="left" line-height="0">
                <fo:block-container background-color="gray" height="3in" width="4in" line-height="normal">
                    <fo:block font-size="34px" font-weight="bold">Name - 5</fo:block>
                    <fo:block font-size="18px">Full Name </fo:block>
                    <fo:block font-size="18px">Company</fo:block>
                    <fo:block font-size="18px">City, State</fo:block>
                </fo:block-container>
            </fo:float>
            <fo:float float="left" line-height="0">
                <fo:block-container background-color="gray" height="3in" width="4in" line-height="normal">
                    <fo:block font-size="34px" font-weight="bold">Name - 6</fo:block>
                    <fo:block font-size="18px">Full Name</fo:block>
                    <fo:block font-size="18px"/>
                    <fo:block font-size="18px">City, State</fo:block>
                </fo:block-container>
            </fo:float>
            <fo:block-container background-color="gray" height="1.3in" width="8in" page-break-after="always" clear="left">
                <fo:block> Text goes here </fo:block>
            </fo:block-container>
            <fo:float float="left" line-height="0">
                <fo:block-container background-color="gray" height="3in" width="4in" line-height="normal">
                    <fo:block font-size="34px" font-weight="bold">Name - 7</fo:block>
                    <fo:block font-size="18px">Full Name</fo:block>
                    <fo:block font-size="18px">Company</fo:block>
                    <fo:block font-size="18px">City, State</fo:block>
                </fo:block-container>
            </fo:float>

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

PDF Result