如何在 ruby​​ 中设置 Prawn 的边距?

发布于 2024-10-10 02:09:24 字数 448 浏览 0 评论 0原文

这是我到目前为止所拥有的,但我需要设置边距:

def send_fax 
    contact = Contact.find_by_id(self.contact_id)

    pdf = Prawn::Document.new
    pdf.font "Times-Roman"
    pdf.move_down(20)
    pdf.text "ATTN: #{contact.first_name} #{contact.last_name}", :size => , :style => :bold
    pdf.text "RE: #{self.subject}"
    pdf.move_down(20)

    pdf.text "#{self.body}"

    OutboundMailer.deliver_fax_email(contact, self, pdf)

  end

This is what I have so far, but I need to set margins:

def send_fax 
    contact = Contact.find_by_id(self.contact_id)

    pdf = Prawn::Document.new
    pdf.font "Times-Roman"
    pdf.move_down(20)
    pdf.text "ATTN: #{contact.first_name} #{contact.last_name}", :size => , :style => :bold
    pdf.text "RE: #{self.subject}"
    pdf.move_down(20)

    pdf.text "#{self.body}"

    OutboundMailer.deliver_fax_email(contact, self, pdf)

  end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

|煩躁 2024-10-17 02:09:24

Prawn::Document.new( :margin => [0,0,0,0] )

:margin:    Sets the margin on all sides in points [0.5 inch]
:left_margin:   Sets the left margin in points [0.5 inch]
:right_margin:  Sets the right margin in points [0.5 inch]
:top_margin:    Sets the top margin in points [0.5 inch]
:bottom_margin: Sets the bottom margin in points [0.5 inch]

http://rdoc.info/github/sandal/prawn/master/Prawn/Document

Prawn::Document.new( :margin => [0,0,0,0] )

:margin:    Sets the margin on all sides in points [0.5 inch]
:left_margin:   Sets the left margin in points [0.5 inch]
:right_margin:  Sets the right margin in points [0.5 inch]
:top_margin:    Sets the top margin in points [0.5 inch]
:bottom_margin: Sets the bottom margin in points [0.5 inch]

http://rdoc.info/github/sandal/prawn/master/Prawn/Document

刘备忘录 2024-10-17 02:09:24

只是在这里添加知识万神殿,但如果您来这里是想使用 Prawn Label gem 来完成此操作,则无法以这种方式设置文档边距。你必须解决这个问题。这是一个快速灵活的代码片段,用于创建带有位于文档边界框内的统一垫的边界框。

pad = 5

pdf.bounding_box([pad, pdf.bounds.height - pad], :width => pdf.bounds.width - (pad * 2), :height => pdf.bounds.height - (pad * 2)) do
    #Draw all your content in this block and it will be padded uniformly by 5
end

如果您使用的是 Prawn 的隐式版本,请从 .bounding_box 和 .bounds 中删除 pdf。

Just adding to the pantheon of knowledge here, but in case you came here looking to do this using the Prawn Label gem, you can't set the document margin this way. You'll have to do a work around. Here's a quick and flexible snippet for creating a bounding box with a uniform pad that sits inside the document bounding box.

pad = 5

pdf.bounding_box([pad, pdf.bounds.height - pad], :width => pdf.bounds.width - (pad * 2), :height => pdf.bounds.height - (pad * 2)) do
    #Draw all your content in this block and it will be padded uniformly by 5
end

Remove the pdf from .bounding_box and .bounds if you're using an Implicit version of Prawn.

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