在 Rails 和 Prawn 中将文本环绕在图像周围
我有一个包含动态图像和动态文本的文档,并且想要图像周围的文本。图像在横向页面上右对齐。这是我到目前为止所得到的:
pdf.bounding_box([0,pdf.bounds.top - 50], :width => pdf.bounds.width, :height => pdf.bounds.height-50) do
pdf.text @article.title, :size => 30, :style => :bold
pdf.text @article.content, :align => :left
# image
pdf.bounding_box([pdf.bounds.right - 250, pdf.bounds.top], :width => 250, :height => 250) do
pdf.image image_path, :width => 250
end
end
文本位于图像的正下方。我尝试这样做ruby prawn如何换行文本围绕对齐的右侧图像? 但它不起作用。
感谢帮助,谢谢。
I have a document with dynamic image and dynamic text and would like the text around the image. The image is right aligned on the landscape page. Here is what I have so far:
pdf.bounding_box([0,pdf.bounds.top - 50], :width => pdf.bounds.width, :height => pdf.bounds.height-50) do
pdf.text @article.title, :size => 30, :style => :bold
pdf.text @article.content, :align => :left
# image
pdf.bounding_box([pdf.bounds.right - 250, pdf.bounds.top], :width => 250, :height => 250) do
pdf.image image_path, :width => 250
end
end
The text goes right underneath the image. I tried doing this ruby prawn how to wrap text around an aligned right image? but it didn't work.
Help is appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您知道图像的宽度和高度,则可以使用 text_box 在图像旁边放置一个文本框,并收集不适合的文本的返回字符串。然后在图像和 text_box 下方创建第二个文本框或普通的 text() 调用,您应该可以开始了。
这个例子应该有帮助:
http://github.com/sandal/prawn/ blob/0.9.1/examples/text/text_box_returning_excess.rb
If you know the width and height of the image, you can use text_box to position a text box next to the image, and collect the returned string of the text that did not fit. Then create a second text box or an ordinary text() call below the image and text_box, and you should be good to go.
This example should help:
http://github.com/sandal/prawn/blob/0.9.1/examples/text/text_box_returning_excess.rb
我对虾没有太多经验,所以这只是一个猜测。您是否尝试过将 pdf.text 语句放在图像边界框之后?
I don't have much experience with prawn, so this is just a guess. Have you tried putting your pdf.text statements after the image bounding box?