在 Rails 和 Prawn 中将文本环绕在图像周围

发布于 2024-08-30 02:16:21 字数 668 浏览 20 评论 0原文

我有一个包含动态图像和动态文本的文档,并且想要图像周围的文本。图像在横向页面上右对齐。这是我到目前为止所得到的:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱,才寂寞 2024-09-06 02:16:21

如果您知道图像的宽度和高度,则可以使用 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

二手情话 2024-09-06 02:16:21

我对虾没有太多经验,所以这只是一个猜测。您是否尝试过将 pdf.text 语句放在图像边界框之后?

pdf.bounding_box([0,pdf.bounds.top - 50], 
   :width => pdf.bounds.width, 
   :height => pdf.bounds.height-50) do 

   # image 
   pdf.bounding_box([pdf.bounds.right - 250, pdf.bounds.top], 
      :width => 250, :height => 250) do 
      pdf.image image_path, :width => 250 
   end 

   pdf.text @article.title, :size => 30, :style => :bold 
   pdf.text @article.content, :align => :left 

end

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?

pdf.bounding_box([0,pdf.bounds.top - 50], 
   :width => pdf.bounds.width, 
   :height => pdf.bounds.height-50) do 

   # image 
   pdf.bounding_box([pdf.bounds.right - 250, pdf.bounds.top], 
      :width => 250, :height => 250) do 
      pdf.image image_path, :width => 250 
   end 

   pdf.text @article.title, :size => 30, :style => :bold 
   pdf.text @article.content, :align => :left 

end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文