我是一个FO新手。
我想使用Xalan和FOP 1.1将XML文档转换为PDF文件
我制作了一个XSL样式表,将源XML文档转换为FO文档。除了一件事之外,XSL样式表运行良好;
源XML
<?xml version="1.0" encoding="utf-8"?>
<root>
...
<order>....</order>
<books>...</book>
<location>...</location>
<item img="a.png" caption="caption1" />
<item img="b.png" caption="caption2" />
<books>...</book>
<books>...</book>
<item img="c.png" caption="caption1" />
<location>...</location>
...
</root>
我希望渲染相邻的项目&#39;图像(外部图形)和标题在一行中的元素。但是我无法确定如何做到这一点。
例如,FO下方呈现为分隔线。当我使用线区域元素时,它根本不会被渲染。 我还试图为每个项目使用表格单元格。元素,它完美地运作。但是我不想使用table / table-cell。 (有很复杂的原因与源XML文档有关,这里无法解释......) 我认为有一些方法可以强制阻止容器作为“线区域”,而不是“阻止区域”。你能帮我吗? (Apache FOP 1.1)
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="main">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="main">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<!-- rendered as separated lines -->
<fo:block>
<!-- Component#1 -->
<fo:block-container>
<fo:block background-color="blue"><fo:external-graphic src="a.png" width="30mm" content-width="scale-down-to-fit" scaling="uniform" /></fo:block>
<fo:block>Caption1</fo:block>
</fo:block-container>
<!-- Component#2 -->
<fo:block-container>
<fo:block background-color="blue"><fo:external-graphic src="b.png" width="30mm" content-width="scale-down-to-fit" scaling="uniform" /></fo:block>
<fo:block>Caption2</fo:block>
</fo:block-container>
</fo:block>
<!-- Using inline-container for each 'item' element, but nothing displaied -->
<!-- Component#1 -->
<fo:inline-container>
<fo:block-container>
<fo:block background-color="blue"><fo:external-graphic src="a.png" width="30mm" content-width="scale-down-to-fit" scaling="uniform" /></fo:block>
<fo:block>Caption1</fo:block>
</fo:block-container>
</fo:inline-container>
<!-- Component#2 -->
<fo:inline-container>
<fo:block-container>
<fo:block background-color="blue"><fo:external-graphic src="b.png" width="30mm" content-width="scale-down-to-fit" scaling="uniform" /></fo:block>
<fo:block>Caption2</fo:block>
</fo:block-container>
</fo:inline-container>
<!-- Using table, work well. but it can not be used for source XML. -->
<fo:table>
<fo:table-body>
<!-- Component#1 -->
<fo:table-cell>
<fo:block-container>
<fo:block background-color="blue"><fo:external-graphic src="a.png" width="30mm" content-width="scale-down-to-fit" scaling="uniform" /></fo:block>
<fo:block>Caption1</fo:block>
</fo:block-container>
</fo:table-cell>
<!-- Component#2 -->
<fo:table-cell>
<fo:block-container>
<fo:block background-color="blue"><fo:external-graphic src="b.png" width="30mm" content-width="scale-down-to-fit" scaling="uniform" /></fo:block>
<fo:block>Caption2</fo:block>
</fo:block-container>
</fo:table-cell>
</fo:table-body>
</fo:table>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
答案 0 :(得分:3)
这是一个老问题,但也许有人可以使用答案。
将带有标签的多个图像放在同一行&#34; line&#34;使用以下代码:
<fo:block>
<fo:inline-container inline-progression-dimension="49.9%">
<fo:block>image1</fo:block>
<fo:block>label1</fo:block>
</fo:inline-container>
<fo:inline-container inline-progression-dimension="49.9%">
<fo:block>image2</fo:block>
<fo:block>label2</fo:block>
</fo:inline-container>
</fo:block>
内联渐进维度显然取决于您要放置的容器数量。