Profile

Nikita Misharin

Developer
Writing stuff on the internet to appear smarter, than
I actually am

Generating pdf with wickedpdf in sidekiq

Recently, I had to generate invoice pdf in a background job. There is a documentation for how to do so, but it seemes overly complicated.

Here is a shorter, more readable version and without unnecessary class_eval

view = ActionView::Base.new('app/views/resources/', {}, ActionController::Base.new)

html = view.render(file: 'show.html.slim', locals: { resource: resource })

WickedPdf.new.pdf_from_string(html)

Returned pdf you can then upload to S3 or **store in a file.

Read Next:

What protected actually does?