由于我不太熟悉xsl:fo,因此不确定正确的术语。我正在创建一些样式表以将html页面转换为pdf,并且除了“段落内”图像外,所有工作都很好。我有一些包含图标的段落,我想将它们转换为xsl:fo。
该html如下所示:
<p>This is a sentence with some icons, like <img src="icon_up"/>, <img src="icon_down"/>, and <img src="icon_right"/></p>
看起来像
This is a sentence with some icons, like [u], [d], and [r]
我正在使用这些模板将其转换为pdf(使用Altova XML / FOP)
<xsl:template match="p">
<fo:block font-size="12pt" line-height="15pt" space-after="12pt">
<xsl:apply-templates select="*|text()"/>
</fo:block>
</xsl:template>
<xsl:template match="img[parent::p]">
<fo:external-graphic src="{@src}" width="100%" content-width="scale-to-fit" scaling="uniform" content-height="100%"/>
</xsl:template>
但我的结果如下:
This is a sentence with some icons, like
[u]
,
[d]
, and
[r]
那么,我如何将其放在一行而不是层叠下来呢?
格式化对象fo:external-graphic
具有两对尺寸:
width
并height
定义图像的分配区域(非正式地,它们定义了通过其查看图像的“窗口”或“孔”)
content-width
并content-height
定义图像 的尺寸
如果width
与height
定义一矩形比定义的一个小的content-width
和content-height
,然后就在图像的一部分是可见的; 在相反的情况下,分配的区域将仅被图像部分占用(您可以在XSL-FO规范的第6.6.5节fo:external-graphic中找到完整的正式定义)。
您的原始模板具有:
<fo:external-graphic src="{@src}" width="100%" .../>
因此,为每个图像分配的区域的宽度等于线宽的100%,从而在下一行中推送以下内容。
为了使较小的图像与周围的文本在同一行中,您可以使用content-width
和content-height
,将它们设置为固定值(例如"1cm"
)或相对于其固有大小的百分比(如您在自己的回答中所做的那样),然后离开width
并height
恢复为默认值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句