【发布时间】:2015-03-09 17:59:34
【问题描述】:
我有两个插件,其中一个插件用于设计报告的页眉和页脚,另一个用于编写 pdf 报告的正文内容。 当页眉高度增加或减少时,pdf 报告的正文内容应根据页眉高度动态上下移动。对此的任何解决方案都会非常有帮助。
def custom_report_pdf
begin
report = CustomReport.find(params[:id].to_i)
paper_margin = report.paper_margin
paper_orientation = report.paper_orientation
paper_size = report.paper_size
unless paper_size.nil?
@page_height = paper_size[:page_height]
@page_width = paper_size[:page_width]
end
@student_ids = []
query = []
@sorted_description =[]
params[:custom_reports].each do |key,value|
@student_ids << key if value.to_i == 1
end
@student_ids = CustomReport.sort_by_first_name(@student_ids)
@student_ids.each do |student_id|
# the content of tinymce description part whole thing is splitted then it is made loop one by one as word
description = report.description.split
description.each_with_index do |word, i|
@value = CustomReport.match_string(query, word, student_id, i, params[:id]).to_s
end
@sorted_description << @value
query = []
end
# if defined? HeaderFooterDesign == 'constant' and HeaderFooterDesign.first.config_key == true
# render :pdf => "#{report.name}"
# else
render :pdf => "#{report.name}",
:orientation => paper_orientation.nil? ? 'Portrait' : paper_orientation,
:page_height => @page_height.nil? ? '27.94cm' : @page_height+"cm",
:page_width => @page_width.nil? ? '21.59cm' : @page_width+"cm",
:margin => paper_margin.nil? ? {:top => '3.2cm',:bottom => '2cm', :left => '2cm',:right => '2.1cm'} : {:top => (paper_margin[:top].to_f+ 3.5).to_s + "cm",:bottom => (paper_margin[:bottom].to_f + 0.2).to_s + "cm", :left => paper_margin[:left]+"cm",:right => (paper_margin[:right].to_f).to_s + "cm" }
# end
rescue Exception => e
Rails.logger.info "Exception in design_custom_reports controller, custom_report_pdf action"
Rails.logger.info e
flash[:notice] = "Sorry, something went wrong. Please inform administration"
redirect_to :action => :index
end
结束
【问题讨论】:
-
这是您定义的单独模块,您在某处调用它,借助定义的方法'custom_pdf_report'
-
这是 pdf 视图的代码部分。 pdf 的标题将来自不同的插件。
-
您可以通过指定
bounding_box [bounds.left, bounds.top - 105], :width => bounds.width , :height => bounds.height do来尝试使用bounding_box,并尝试在其中调用您的标题。所以根据你的header高度,这个盒子的大小会增加和减少 -
能否请您详细解释一下如何使用它。
标签: css ruby-on-rails pdf wicked-pdf