Skip to content

Instantly share code, notes, and snippets.

@janfoeh
Created April 12, 2015 20:51
Show Gist options
  • Save janfoeh/ae639418a321bf70520a to your computer and use it in GitHub Desktop.
Save janfoeh/ae639418a321bf70520a to your computer and use it in GitHub Desktop.
Rails 4.2 WickedPDF renderer class
# 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