Created
April 12, 2015 20:51
-
-
Save janfoeh/ae639418a321bf70520a to your computer and use it in GitHub Desktop.
Rails 4.2 WickedPDF renderer class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see https://github.com/rails/rails/issues/14125#issuecomment-44547905 | |
# for clues about the Rails 4.1 specific changes | |
class PdfRenderer < AbstractController::Base | |
include ActionController::Helpers | |
include AbstractController::Rendering | |
include ActionView::Layouts | |
append_view_path "#{Rails.root}/app/views" | |
View = Struct.new(:layout, :action, :locals) | |
def render_pdf(view) | |
html = render_to_string( | |
layout: view.layout, | |
action: view.action, | |
locals: view.locals | |
) | |
WickedPdf.new.pdf_from_string(html, :margin => {top: 0, bottom: 0, left: 0, right: 0}, :disable_smart_shrinking => true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment