大虾-如何将pdf文档中常见的东西概括成一个单独的模块以供代码复用?
我正在使用 Rails Prawn 生成 pdf 文件。现在我能够生成包含我需要的所有必要内容的 pdf(例如表格、页眉、页脚、徽标、边框等...)。现在我需要在单独的模块内的方法中使用常见的东西(标题,页脚,边框)并从我的原始程序中调用此方法?
我原来的程序: 旅行报告.rb 模块 TravelReport
包括标题 def self.generate(start_ts, end_ts, format_type, obu_ids, 间隔) Prawn::Document.generate("public/test.pdf") 做
边框
page_count.times do |i|
go_to_page(i+1)
Header.border
end
页眉和边界线
page_count.times do |i|
go_to_page(i+1)
ask = "public/ashok.jpg"
image ask, :at => [15, 750], :width => 120
alert = "public/alert.jpg"
image alert, :at => [410, 740], :width => 120
end
页脚
page_count.times do |i|
go_to_page(i+1)
lazy_bounding_box([bounds.left+30, bounds.bottom + 20], :width => 100) {
text "Bypass Report"
}.draw
end
end
单独的边框模块 模块头 #class Cheader <大虾::文档::BoundingBox #包括虾 def self.border
pdf = Prawn::Document.new
pdf.bounding_box([5, 705], :width => 540, :height => 680) do
pdf.stroke_bounds
end
end
#end
end
此代码不会创建任何边框...知道如何为此创建单独的模块吗???
I am using the Rails Prawn to generate pdf files. Now that i am able to generate pdf with all necessary things that i need(eg. table, header, footer, logo, borders etc...). Now I need to use the common things(header, foooter, borders) in a method inside separate module and call this method from my original program?
My original program:
travel_report.rb
module TravelReport
include Header
def self.generate(start_ts, end_ts, format_type, obu_ids, interval)
Prawn::Document.generate("public/test.pdf") do
Borders
page_count.times do |i|
go_to_page(i+1)
Header.border
end
Header and Boundary Lines
page_count.times do |i|
go_to_page(i+1)
ask = "public/ashok.jpg"
image ask, :at => [15, 750], :width => 120
alert = "public/alert.jpg"
image alert, :at => [410, 740], :width => 120
end
footer
page_count.times do |i|
go_to_page(i+1)
lazy_bounding_box([bounds.left+30, bounds.bottom + 20], :width => 100) {
text "Bypass Report"
}.draw
end
end
Separate Module for Borders
module Header
#class Cheader < Prawn::Document::BoundingBox
#include Prawn
def self.border
pdf = Prawn::Document.new
pdf.bounding_box([5, 705], :width => 540, :height => 680) do
pdf.stroke_bounds
end
end
#end
end
This code doesnt creates any border... Any idea how to create separate module for this????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这工作正常...
This works fine...