rails gem prawn、图像和锚点 [英] rails gem prawn, image and anchor
问题描述
你能告诉我如何插入图片,例如第 20 页的链接吗?我知道如何用普通文本制作:
Can you tell me how to insert image which will be a link to for example page 20? I know how to make with normal text:
text "<link anchor='page20'>Go to page 20</link>", :inline_format=>true
然后在第 20 页我有
and then on page 20 I have
add_dest('page20', dest_fit(page.dictionary))
但是如何用图像来做到这一点?
but how to do this with image ?
推荐答案
部分感谢 lightswitch05 在正确的方向,我找到了通过这种不优雅的方式获得我想要的效果的方法:
Partly thanks to lightswitch05 for some prodding in the right direction, I've found a way to get the effect I want through this inelegant way:
- 在
bounding_box
中插入图像(页面cursor
位于图像底部) - 将光标移回图像顶部
- 在图像上插入文本链接(在我的例子中,我只是使用了许多竖线
|
"来覆盖图像) - 目视确认可点击链接区域与图片的边界大致相同
- 将文本链接设为透明,瞧,您就像在点击图片一样.
- Insert an image in a
bounding_box
(the pagecursor
is at this point at the bottom of the image) - Move the cursor back up to the top of the image
- Insert a text link over the image (in my case I just used however many vertical bars '
|
' were needed to cover the image) - Confirm visually that the clickable link area is about the same as the boundaries of the image
- Make the text link transparent, and voilà, it looks like you're clicking the image.
这是一些示例代码(测量不准确;涉及很多调整):
Here's some example code (measurements not exact; there was a lot of tweaking involved):
bounding_box([0, cursor], width: 35) do
image open("http://mysite.com/remote_image.jpg"),
fit: [35, 35],
align: :center
move_up 35
transparent(0) do
formatted_text([{
text: "|||", # placeholder
size: 40,
link: "http://example.com/"
}], align: :center)
end
# stroke_bounds
end
不用说,这次经历让我更多地关注 Wicked PDF,以便做我想对 PDF 做的事情.
Needless to say, this experience has got me looking a bit more at Wicked PDF in order to do what I think I want to do with PDFs.
我确信存在更好/更优雅的解决方案,所以我不打算考虑这是我的最终答案.
I'm sure a better/more elegant solution exists, so I'm not planning on considering this my final answer.
这篇关于rails gem prawn、图像和锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!