在ruby on rails应用程序中,我使用prawn(o.12.0)和prawnto创建了pdf。在pdf中有一个表,问题是我无法将表对齐到中心。
当给出:align => center时,它会抛出一个未定义的错误。
我该如何解决这个问题。
pdf.bounding_box([5, 705], :width => 530, :height => 680) do
pdf.stroke_bounds
pdf.move_down(20)
pdf.text "Demographics", :size => 15, :style => :bold, :align => :center
invoiceData = [["Facebook Pushes - Total users","Users Shared Exercise For Week","Users Shared Exercise For Day","Users Share TestResult"],
[100","20","50","30"]]
pdf.table(invoiceData,:row_colors => ["FDFFFF", "FFFFFF"], :cell_style => { :border_width => 0.1,:border_color=> 'C1C1C1' }) do |table|
end
pdf.bounding_box([pdf.bounds.right - 50,pdf.bounds.bottom], :width => 60, :height => 20) do
pagecount = pdf.page_count
pdf.text "Page #{pagecount}"
end
end
[屏幕快照]
答案 0 :(得分:1)
pdf.bounding_box([5, 705], :width => 530, :height => 680) do
pdf.stroke_bounds
pdf.move_down(20)
pdf.text "Demographics", :size => 15, :style => :bold, :align => :center
pdf.bounding_box([25,pdf.bounds.top-100], :width => 516, :height => 680) do
invoiceData = [["Facebook Pushes - Total users","Users Shared Exercise For Week","Users Shared Exercise For Day","Users Share TestResult"],
[100","20","50","30"]]
pdf.table(invoiceData,:row_colors => ["FDFFFF", "FFFFFF"], :cell_style => { :border_width => 0.1,:border_color=> 'C1C1C1' }) do |table|
end
end
pdf.bounding_box([pdf.bounds.right - 50,pdf.bounds.bottom], :width => 60, :height => 20) do
pagecount = pdf.page_count
pdf.text "Page #{pagecount}"
end
end
通过在表格上方定义一个新的边界框,我们可以解决这个问题
pdf.bounding_box([25,pdf.bounds.top-100], :width => 516, :height => 680) do