You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/config/initializers/pdfkit.rb

28 lines
897 B

6 years ago
PDFKit.configure do |config|
6 years ago
# config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf'
config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf'
6 years ago
config.default_options = {
6 years ago
encoding: "UTF-8",
6 years ago
page_size: 'A4',
print_media_type: true,
dpi: 300,
debug_javascript: true,
javascript_delay: 500,
6 years ago
# quiet: false
stop_slow_scripts:false,
no_stop_slow_scripts: true
6 years ago
}
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)