gpt4 book ai didi

ruby - Prawn :创建一个带有标题横幅和重复标题表的PDF

转载 作者:太空宇宙 更新时间:2023-11-03 16:31:49 26 4
gpt4 key购买 nike

目标是:创建具有标题横幅和重复标题表的 PDF
问题是:如果表格开始新页面,pdf.move_down 不起作用

CODE:
# repeat drawing in every page
pdf.repeat(:all, :dynamic => true) do
pdf.font("#{Rails.root}/vendor/pdffonts/ThonburiBold.ttf") do
pdf.font_size = 8

pdf.float { pdf.text "Time: #{tt}", :align => :left }
pdf.float { pdf.text "Page #{pdf.page_number}", :align => :right }
pdf.float { pdf.text "Inquiry Name: #{page_title}", :align => :center }

pdf.move_down 15

pdf.float { pdf.text "AS OF #{Time.now.to_date}", :align => :center }


pdf.move_down 40 ## move down to draw the following table
pdf.stroke_horizontal_rule
end

## ... building big_data_array for table ...

table_config = {
:header => true,
:row_colors => ["FFFFFF", "F0F0F0"],
:cell_style => { :padding => 1 }
}

# draw a long table
pdf.table(big_data_array, table_config) do |t|
t.before_rendering_page do |c|
pdf.move_down 40 ## try to add margin-top before render the table in every page
end
t.row(0).background_color = "DADADA"
# style rows and cells ...
end

最佳答案

我决定修改 Prawn::Table 方法 draw 以接受我的偏移值

module Prawn
class Table
def set_before_render_offset(y = 0)
@user_offset = y
end

def draw
...
# start a new page or column
@pdf.bounds.move_past_bottom
if cell.row > 0 && @header
header_height = add_header(cells_this_page, @pdf.cursor - @user_offset, cell.row-1)
else
header_height = 0
end
offset = @pdf.y - cell.y - header_height - @user_offset
started_new_page_at_row = cell.row
...
end
end

关于ruby - Prawn :创建一个带有标题横幅和重复标题表的PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14684072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com