xsl-fo外部图形中具有坐标的Area属性 [英] Area attribute in xsl-fo external-graphic with coordinates
问题描述
我有一个需要使用xsl-fo描绘图像的要求,并且用户应该能够在图像的文本/特定位置内单击.为了进一步解释,
I have a requirement where I need to portray an image using xsl-fo and the user should be able to click within the text / particular location of the image. To explain it further,
- 我有一张图片
- 它包含文字
- 我具有文本出现位置的坐标,需要为这些坐标提供超链接.
因此,当我单击文本时,应该可以遍历PDF文档中的另一个位置.
So, when I click on the text, I should be able to traverse to another location in the PDF document.
我尝试使用<area>
标记提及<fo:block>
中的坐标,但是它不起作用.
我的Fo结构如下:
I have tried with <area>
tag mentioning the co-ordinates within <fo:block>
, but it does not work.
My Fo structure is as follows:
<fo:block> <fo:external-graphic content-width="scale-to-fit" content-height="100%" width="100%" src="figures/test.png"/><area shape="rect" coords="148,147,195,162" <fo:basic-link>xyz</fo:basic-link></area>
</fo:block>
您能告诉我是否有人尝试过这种方法并帮助我吗?
Could you please let me know if anyone has tried something like this and help me out?
推荐答案
虽然XSL-FO 不具有图像映射(类似于HTML中的MAP
元素),但有可能使用嵌入式SVG文档可获得相同的结果.
While XSL-FO does not have image maps (something analogous to the MAP
element in HTML), it is possible to use an embedded SVG document to achieve the same result.
看看这个例子:
<fo:block>
<fo:instream-foreign-object>
<svg width="5cm" height="3cm" viewBox="0 0 5 3" version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image x="0" y="0" width="5" height="3" xlink:href="image.png"/>
<a xlink:href="http://www.w3.org">
<rect x="1" y="2" width="3" height="1"
fill="#AAFFFF" stroke="none" opacity="0"/>
</a>
</svg>
</fo:instream-foreign-object>
</fo:block>
在svg文档中:
-
image
元素放置位图图像,其大小与文档的viewBox相同 -
a
元素定义了链接目标 -
a
内的rect
元素定义了可点击区域
- an
image
element places the bitmap image, having the same size of the document viewBox - an
a
element defines the link destination - a
rect
element inside thea
defines the clickable area
我用FOP 2.1测试了这个示例,并且可以使用几个 caveat
I tested this example with FOP 2.1 and it works, with a couple of caveat:
- 为了使可点击矩形完全透明,我使用了
opacity="0"
;我尝试使用fill="none" stroke="none"
,但此方法不起作用,可能是因为矩形已完全丢弃/忽略了没有可见标记的矩形 - 即使在SVG中使用
ellipse
元素,PDF中的可单击区域也是矩形的.
- in order to make the clickable rectangle completely transparent I used
opacity="0"
; I tried usingfill="none" stroke="none"
but this was not working, probably because the rectangle was completely discarded / ignored not having any visible mark - the clickable area in the PDF is rectangular even when using an
ellipse
element in the SVG
这篇关于xsl-fo外部图形中具有坐标的Area属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!