rap*_*pot 3 xml xsl-fo xslt-1.0 apache-fop
我是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>
Run Code Online (Sandbox Code Playgroud)
我想用图像(外部图形)和标题在一行中渲染相邻的“项目”元素。但是,我不确定如何完成。
例如,下面的 FO 呈现为分隔线。当我使用线区域元素时,它根本不会被渲染。我还尝试为每个“项目”元素使用表格单元格,并且效果很好。但是我不想使用表格/表格单元格。(与源 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>
Run Code Online (Sandbox Code Playgroud)
小智 6
这是一个老问题,但也许有人可以使用答案。
要将带有标签的多个图像放在同一“行”中,请使用以下代码:
<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>
Run Code Online (Sandbox Code Playgroud)
inline-progression-dimension 显然取决于您要放置的容器数量。