2

我正在使用 Rails Prawn 生成 pdf 文件。现在我可以生成包含我需要的所有必要内容的 pdf(例如表格、页眉、页脚、徽标、边框等)。现在我需要在单独模块内的方法中使用常见的东西(页眉、页脚、边框)并从我的原始程序中调用这个方法?

我原来的程序:travel_report.rb 模块 TravelReport

包括 Header def self.generate(start_ts, end_ts, format_type,obu_ids, interval) 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 

Borders 模块的单独模块 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

结尾

此代码不会创建任何边框...知道如何为此创建单独的模块????

4

1 回答 1

1
#create a separate module

#program



include HeaderFooter
Prawn::Document.generate("public/test.pdf") do |pdf|
pdf.page_count.times do |i|
        pdf.go_to_page(i+1)
        HeaderFooter.border(pdf)      
        #render :partial => 'header', :locals => {:ppdf => pdf}
      end

#Header and Boundary Lines      
      pdf.page_count.times do |i|
        pdf.go_to_page(i+1)
          HeaderFooter.image(pdf)
      end
#footer
      pdf.page_count.times do |i|
       pdf.go_to_page(i+1)
        HeaderFooter.footer(pdf)
      end
    end 




create a module to define the methods(header_footer.rb)
module HeaderFooter
    #Method for border creation in pdf
    def self.border(ppdf)
       ppdf.bounding_box([5, 705], :width => 540, :height => 680) do
       ppdf.stroke_bounds
      end
    end
    #method to create the logos in the pdf
    def self.image(ppdf)
      ask = "public/ashok.jpg"
      ppdf.image ask, :at => [15, 750], :width => 120
      alert = "public/alert.jpg"
      ppdf.image alert, :at => [410, 740], :width => 120
    end
    #method to print footer text in the pdf
    def self.footer(ppdf)
      ppdf.lazy_bounding_box([ppdf.bounds.left+30, ppdf.bounds.bottom + 20], :width => 100) {
      ppdf.text "Bypass Report"
       }.draw
    end

end

这工作正常...

于 2010-10-20T10:01:53.917 回答