Last active
December 20, 2015 19:19
-
-
Save acapilleri/6182210 to your computer and use it in GitHub Desktop.
Generate PDF with wkhtmltopdf without any required gems. In this case I use rails, but it's flexible for any ruby frameworks or just for simply ruby app
This file contains hidden or 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
def show | |
@pet = Pet.find(params[:id]) | |
tempfile = Tempfile.new(@pet.id.to_s) | |
render_file = Tempfile.new(@pet.id.to_s + '.html') | |
buffer = render 'show.pdf.erb', layout: false | |
render_file.write(buffer.first) | |
html = "#{render_file.path}.html" | |
system "mv #{render_file.path} #{html} && wkhtmltopdf #{html} #{tempfile.path}" | |
send_file tempfile.path, type: 'application/pdf' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment