当我尝试以下代码时:
text "Hello "
text "World"
他们在 World 之上渲染 Hello,而不是在 Hello 之后立即渲染 World。我在一行中需要的文本上有一些复杂的格式(突出显示、不同的字体大小等)。我知道 :inline_formatting
选项存在,但使用该选项似乎太复杂了。
我有以下代码:
highlight_callback.rb:
class HighlightCallback
def initialize(options)
@color = options[:color]
@document = options[:document]
end
def render_behind(fragment)
original_color = @document.fill_color
@document.fill_color = @color
@document.fill_rectangle(fragment.top_left,
fragment.width,
fragment.height)
@document.fill_color = original_color
end
end
order.pdf.prawn:
highlight = HighlightCallback.new(:color => 'ffff00', :document => self)
#code....
text "Authorized Signature: "
formatted_text [{:text => "_" * 15, :callback => highlight }], :size => 20
正在生成附加图像。如何让签名行与正文处于同一层级?
最佳答案
ruby 2.5.1
rails 5.2.0
将方法 text
更改为 text_box
就足够了,即:
bounding_box([0, cursor], width: 540, height: 40) do
stroke_color 'FFFF00'
stroke_bounds
date = 'Date: '
text_box date, style: :bold
text_box DateTime.now.strftime('%Y/%m/%d'), at: [bounds.left + width_of(date), cursor]
text_box "Signature ________________", align: :right
end
示例:
关于ruby-on-rails - Prawn/PDF : Multiple formats/text on one line?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42278149/