forgeplus/config/initializers/pdfkit.rb

28 lines
897 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PDFKit.configure do |config|
config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf'
# config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf'
config.default_options = {
encoding: "UTF-8",
page_size: 'A4',
print_media_type: true,
dpi: 300,
debug_javascript: true,
javascript_delay: 500,
# quiet: false
stop_slow_scripts:false,
no_stop_slow_scripts: true
}
end
# 原有方法会给所有含 head 标签的地方插入css导致html类实训代码块渲染异常
module FixStylesheetAppend
def append_stylesheets
raise ImproperSourceError.new('Stylesheets may only be added to an HTML source') if stylesheets.any? && !@source.html?
stylesheets.each do |stylesheet|
@source.to_s.insert(0, style_tag_for(stylesheet))
end
end
end
PDFKit.prepend(FixStylesheetAppend)