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

25 lines
773 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

PDFKit.configure do |config|
config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf'
config.default_options = {
page_size: 'A4',
print_media_type: true,
dpi: 300,
debug_javascript: true,
javascript_delay: 500,
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)