我有一个报告,我正在自定义一个视图以在两个不同的列中显示一个表,以节省打印空间。我可以使用内联和常规CSS样式(.crew-report
)在HTML视图中使用它,但是当我在pdf视图中运行它时,更改不会显示。如何使column-count:2
坚持下去?
我遗漏了大多数属性定义,因为报表本身可以很好地呈现,并且当以pdf形式呈现时,该问题表现为样式丢失:
以下是相关视图:
_report_base.html.erb:
<% if params[:type] == "crew" %>
<div class="crew-report">
<%= render 'listings/reports/report_base_table.html.erb' %>
</div>
<%else%>
<%= render 'listings/reports/report_base_table.html.erb' %>
<% end %>
</div>
这是CSS(重复,但是在优化之前,我正在尝试无耻的绿色):
.crew-report {
column-count: 2;
}
@media print {
.crew-report {
column-count: 2;
}
}
通过此调用呈现pdf,除了没有调用乘员报告类之外,该函数还起作用:
report.pdf.erb:
<%= wicked_pdf_stylesheet_link_tag "application" -%>
<div class="pdf-wrapper">
<%= render 'listings/reports/report_base.html.erb', total_column_count: @total_column_count, attributes: @attributes, attributes_for_totaling: @attributes_for_totaling %>
</div>
最后是wicked_pdf呼叫:
listings_controller.rb:
respond_to do |format|
format.html { render 'listings/reports/report' }
format.pdf do
@file_name = "$$$#{params[:type]}_report_"
@file_name += "#{params[:state]}_products_" if params[:state].present?
@file_name += "grouped_by_#{params[:grouped_by]}_" if
params[:grouped_by].present?
@file_name += "for_listing_#
{@listing.name.downcase.parameterize.underscore}"
render template: 'listings/reports/report.pdf.erb',
pdf: @file_name,
encoding: "UTF-8",
page_size: "Letter",
zoom: 0.6,
image_quality: 300,
grayscale: true,
disposition: params.key?('download') ? 'attachment' : 'inline',
show_as_html: params.key?('debug')
end
end