Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何垂直填充表格?_Java_Xml_Pdf_Xsl Fo_Apache Fop - Fatal编程技术网

Java 如何垂直填充表格?

Java 如何垂直填充表格?,java,xml,pdf,xsl-fo,apache-fop,Java,Xml,Pdf,Xsl Fo,Apache Fop,这是我不久前发布的后续问题 我有以下xsl样式表: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo"> <xsl:template

这是我不久前发布的后续问题

我有以下xsl样式表:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
  <xsl:template match="barcode-list">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
          <fo:region-body/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simpleA4">
        <fo:flow flow-name="xsl-region-body">
          <fo:block font-size="14pt">
          <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="3pt">    
            <fo:table-column column-width="50%"/>
            <fo:table-column column-width="50%"/>
            <fo:table-body>
              <xsl:apply-templates select="item"/>
            </fo:table-body>
          </fo:table>
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
     </fo:root>
  </xsl:template>
  <xsl:template match="item">
    <fo:table-cell text-align="center">
      <xsl:if test="position() mod 2 = 1">
        <xsl:attribute name="starts-row">true</xsl:attribute>
      </xsl:if>
      <fo:block>
        <fo:external-graphic height="scale-to-fit" width="100%" content-height="scale-to-fit" content-width="scale-to-fit">
          <xsl:attribute name="src">url('<xsl:value-of select="image"/>')</xsl:attribute>
        </fo:external-graphic>
      </fo:block>
      <fo:block>
        <fo:external-graphic height="scale-to-fit" width="100%" content-height="scale-to-fit" content-width="scale-to-fit">
          <xsl:attribute name="src">url('<xsl:value-of select="barcode"/>')</xsl:attribute>
        </fo:external-graphic>
      </fo:block>
      <fo:block wrap-option="wrap">
        <xsl:value-of select="name"/>
      </fo:block>
    </fo:table-cell> 
  </xsl:template>
</xsl:stylesheet>
理想情况下,我希望移动到页面末尾的下一列,并在下一页的第一列重新开始,但我认为这是不可能的

这是我的xml的一个示例:

<barcode-list>
   <item>
      <name>the-barcode</name>
      <barcode>file:///d:/pdf/barcode.png</barcode>
      <image>file:///d:/test.png</image>
      <format>CODE_128</format>
   </item>
   ...
</barcode-list>

条形码
file:///d:/pdf/barcode.png
file:///d:/test.png
代码128
...
我发现留言板上的条目似乎提出了一个解决方案,但我无法理解它的作用


有谁能给我一些关于如何开始的建议吗

使用两列文档布局,您的内容块(带有两个图像和一个标签)将沿页面向下流动,然后进入下一列。这将在随后的几页中继续。下面是一个例子和结果。需要注意的几点:

  • 通过向区域主体添加列计数,可以实现两列
  • 包含重复内容的每个容器都位于块容器中,并将keep-together.In-column设置为“always”,以确保两个图像和标签都在一起,而不是跨列或页面拆分
  • 我确实更改了您的图形规格,因为“适合比例”的宽度/高度不正确
FO代码示例(注意,我在这里只显示了前几个块,并对它们进行了编号以显示顺序):


对象名称1
对象名称2
9个块的样本输出:


创建两列文档,而不是table@KevinBrown这是否允许我自动转到页面末尾的下一列,或者它基本上会在第一页的第二列开始之前填充所有页面的第一列?两列文档会填充左边的列,然后填充右边的列,在下一页重新开始,依此类推。@KevinBrown听起来很像我想要达到的目标。你介意把这个作为回答吗?理想的情况是用一个小例子?好的,我会在大约一个小时内把你的样本布局整理成一个完整的文档。太棒了,正是我想要的。谢谢
<barcode-list>
   <item>
      <name>the-barcode</name>
      <barcode>file:///d:/pdf/barcode.png</barcode>
      <image>file:///d:/test.png</image>
      <format>CODE_128</format>
   </item>
   ...
</barcode-list>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
    <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
        <fo:region-body column-count="2"/>
    </fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
    <fo:flow flow-name="xsl-region-body">
        <fo:block-container font-size="14pt"  text-align="center" keep-together.within-column="always">
            <fo:block>
                <fo:external-graphic src="url('box.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/>                   
            </fo:block>
            <fo:block>
                <fo:external-graphic src="url('brick.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/>
            </fo:block>
            <fo:block wrap-option="wrap">
                Object Name 1
            </fo:block>
        </fo:block-container>

        <fo:block-container font-size="14pt"  text-align="center" keep-together.within-column="always">
            <fo:block>
                <fo:external-graphic src="url('box.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/>                   
            </fo:block>
            <fo:block>
                <fo:external-graphic src="url('brick.jpg')" height="100%" width="100%" content-height="scale-to-fit" content-width="scale-to-fit"/>
            </fo:block>
            <fo:block wrap-option="wrap">
                Object Name 2
            </fo:block>
        </fo:block-container>