gpt4 book ai didi

xml - 在 FO 中将多个 block 容器渲染为内联

转载 作者:行者123 更新时间:2023-12-04 02:07:13 25 4
gpt4 key购买 nike

我是 FO 新手。

我想使用 Xalan 和 FOP 1.1 将 XML 文档转换为 PDF 文件

我制作了一个 XSL 样式表,将源 XML 文档转换为 FO 文档。除了一件事,XSL 样式表运行良好;

源代码

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

我想用图像(外部图形)和标题在一行中渲染相邻的“项目”元素。但是我不确定该怎么做。

例如,下面的 FO 呈现为分隔线。当我使用线区域元素时,它根本不会被渲染。我还尝试为每个“项目”元素使用表格单元格,并且效果很好。但是我不想使用表格/表格单元格。 (原因很复杂,与源XML文档有关,这里无法解释...)我认为有一些方法可以强制将 block 容器作为“行区域”,而不是“ block 区域”。你能帮我吗?(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>

最佳答案

这是一个老问题,但也许有人可以使用答案。

要将带有标签的多个图像放在同一“行”中,请使用以下代码:

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

inline-progression-dimension 显然取决于你要放置的容器的数量。

关于xml - 在 FO 中将多个 block 容器渲染为内联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23621194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com