开发者

Rails, prawn and dynamic table

I am doing a merchant site. This site must have a voucher.

This voucher is a pdf file generated by Prawn gem.

    items = obtain_items
        Prawn::Document.generate "public/#{self.saving.profile.user.id}/PDFs/order_#{self.id}.pdf" do |pdf|
          pdf.font "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"

          pdf.repeat :all do
            # header
              pdf.image "public/images/fishle-logo-small.png", :at => [480, 735]
              pdf.draw_text "Orden Nro. #{self.id}", :at => [0, 720]
              pdf.draw_text "#{Date.today}", :at => [0, 680]
              pdf.text "Fishle", :size => 36, :align => :center

              # footer
              pdf.draw_text "Fishle.com", :at => [200, 0], :size => 24, :color => "#ff0000"
          end

          #pdf p开发者_运维问答oner texto numero de orden, debajo fecha, numero de pagina debajo de fecha
          #PDF OTROS DATOS COMO INFO CLIENTE, Y DESC ORDEN

          #NOW PRINT IN PDF A TABLE WITH INFORMATION ABOUT ORDER
          pdf.move_down(80)
          pdf.table items, :header => true, :column_widths => {0 => 35, 1 => 80, 2 => 195, 3 => 70, 4 => 70, 5 => 86, }, :row_colors => ["F0F0F0", "FFFFCC"]
          pdf.move_down(10)
          pdf.text "Precio Total:#{self.movements.first.debit_ammount}", :align => :right
          #NOW PRINT THE FOOTER WITH COM INFO ABOUT FISHLE

          10.times do
            pdf.start_new_page
          end
          #NOW PRINT THE PAGE NUMBER
          pdf.page_count.times do |i|
            pdf.go_to_page(i+1)
            pdf.draw_text "Página #{(i+1)} de #{pdf.page_count}", :at => [0, 700]
          end
end

Now my problem is: The site implements a cart which could have n items, so i should generate a table dynamically. This table should be move_down(80) from header and above the footer.

How could i generate this table with prawn?

I think this solution.

First create the header and footer in a box with absolute height and width. Then i create the table so the heigth of header push down the table content. The footer push up the table. So when i start a new page the table location will be ok.

My questions is:

  • How could I create this boxes for header and footer which push the table?

Thanks in advance.


I could resolve my problem. I use margins when create the document and then the header and footer position are set as absolute positions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜