【问题标题】:Wrap text around an image in rails and prawn在 rails and prawn 中将文本环绕在图像周围
【发布时间】:2011-02-11 04:08:00
【问题描述】:

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

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 how to wrap text around an aligned right image?,但没有成功。

非常感谢您的帮助,谢谢。

【问题讨论】:

标签: ruby-on-rails ruby pdf-generation prawn prawnto


【解决方案1】:

如果你知道图片的宽度和高度,你可以使用text_box在图片旁边定位一个文本框,收集不适合的文本的返回字符串。然后在 image 和 text_box 下方创建第二个文本框或普通的 text() 调用,你应该可以开始了。

这个例子应该有助于: http://github.com/sandal/prawn/blob/0.9.1/examples/text/text_box_returning_excess.rb

【讨论】:

    【解决方案2】:

    我对虾没有太多经验,所以这只是一个猜测。您是否尝试过将 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
    

    【讨论】:

    • 好主意,但这只会使文本从图像下方开始,而不是与图像对齐。如果我事先调用 move_up,那么文本会出现在图像前面。
    • 好的,谢谢,只是尝试一下。看起来您发布的堆栈溢出链接是错误的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    相关资源
    最近更新 更多