Tuesday, 15 February 2011

ruby on rails 3 - wicked-pdf: Error: PDF could not be generated -



ruby on rails 3 - wicked-pdf: Error: PDF could not be generated -

i trying create pdf order receipts on our app (on heroku). running pdf generator delayed job. have: -created bin folder in root of app -added binaries (x86-64) folder -added wicked pdf gem gemfile

i testing on our staging app.

this error i'm getting:

error: failed execute: ["/app/vendor/bundle/bin/wkhtmltopdf", "-q", "--page-size", "letter", "file:///tmp/wicked_pdf20141022-213-3dpi58.html", "/tmp/wicked_pdf_generated_file20141022-213-1tqzjod.pdf"] error: pdf not generated! command error: /app/vendor/bundle/ruby/2.0.0/gems/bundler-1.6.3/lib/bundler/rubygems_integration.rb:305:in 'block in replace_bin_path': undefined method name' nil:nilclass (nomethoderror) /app/vendor/bundle/bin/wkhtmltopdf:16:in

any ideas on may going on here? i'm @ bit of loss.

code:

#config/initializers/wicked-pdf.rb wickedpdf.config |config| if rails.env == 'production' config.exe_path = rails.root.to_s + "/bin/wkhtmltopdf-amd64" else if /darwin/ =~ ruby_platform config.exe_path = '/usr/local/bin/wkhtmltopdf' else raise "unabletolocatewkhtmltopdf" end end end

i'm calling queue job in order controller

#jobs/pdf_receipt_job class pdfreceiptjob < struct.new(:order_id) def perform order = order.find(order_id) # create instance of actionview, can utilize render method outside of controller view = actionview::base.new(actioncontroller::base.view_paths, {}) html_template = view.render(file: "order/receipt_attachment.html.erb", locals:{order:order}) # utilize wicked_pdf gem create pdf html receipt template pdf_receipt = wickedpdf.new.pdf_from_string(html_template, :page_size => 'letter') # save pdf disk. later, stored in fog, sent s3, saved our db pdf_path = rails.root.join("tmp", "marmoset-receipt#{order.id}.pdf") #ex: @ tmp/marmoset-receipt215.pdf file.open(pdf_path, 'wb') |file| file << pdf_receipt end end end

the receipt template (to become pdf receipt):

#views/order/receipt_attachment.html.erb <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-language" content="en-us" /> <title>order receipt marmoset</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <div style="width: 75%"> <header> <div style="display: inline; width:100%"> <img src="http://stillmotionblog.com/wp-content/uploads/2013/08/rgb-marmoset-seal-purple.png" alt="marmoset" style="height: 200px; padding:20; float:left"> <h3 style="font-family: helvetica; float:right; color:gray;">order number: <%= order.id %></br> charge key: <%= order.stripe_charge_key %> </h3> </div> </header> <div style="margin: 0 auto"> <table cellpadding="5" cellspacing="2" summary="order receipt" width="100%" style="font-family: georgia;"> <thead> <tr> <th bgcolor="#8a4fab" style="color:white" scope="col">track</th> <th bgcolor="#8a4fab" style="color:white" scope="col">license</th> <th bgcolor="#8a4fab" style="color:white" scope="col">price</th> </tr> </thead> <tbody style="font-family: georgia;"> <% order.line_items.each |line_item| %> <tr> <td bgcolor="#ebebeb" style="font-family: georgia; color: #5c5c5c"><%= line_item.track.display_name %></td> <td bgcolor="#ebebeb" style="font-family: georgia; color: #5c5c5c"><%= line_item.license.display_name %></td> <td bgcolor="#ebebeb" style="font-family: georgia; color: #5c5c5c"><%= number_to_currency line_item.price %></td> </tr> <% end %> <tr> <td colspan="2" style="text-align: right;font-family: georgia; color: #5c5c5c">subtotal</td> <td style="font-family: georgia; color: #5c5c5c"><%= number_to_currency order.price %></td> </tr> <% if order.discount > 0 %> <tr> <td colspan="2" style="text-align: right;font-family: georgia; color: #5c5c5c">discount</td> <td style="font-family: georgia; color: #5c5c5c">-<%= number_to_currency order.discount %></td> </tr> <% end %> <tr> <td colspan="2" style="text-align: right;font-family: georgia; color: #5c5c5c ">total</td> <td style="font-family: georgia; color: #5c5c5c"><%= number_to_currency order.total %></td> </tr> </tbody> </table> </div> <hr style="margin: 30px 0px 30px 0px"> <p style="font-family: georgia; color: #5c5c5c">licensing info order:</p> <ul style="font-family: georgia; color: #5c5c5c"> <% order.line_items.map{|l| l.license}.uniq.each |license| %> <li><strong><%= license.name %> <%= "(#{license.range.html_safe})" if license.range.present? %>:</strong> <ul> <% if license.permitted_content.present? %> <li> <b>permitted content:</b> <%= license.permitted_content.html_safe %> </li> <% end %> <% if license.non_permitted_content.present? %> <li> <b>non-permitted content:</b> <%= license.non_permitted_content.html_safe %> </li> <% end %> <% if license.number_of_uses.present? %> <li> <b>number of uses:</b> <%= license.number_of_uses %> </li> <% end %> <% if license.distribution.present? %> <li> <b>distribution:</b> <%= license.distribution %> </li> <% end %> <% if license.term.present? %> <li> <b>lifespan:</b> <%= license.term %> </li> <% end %> </ul> </li> <% end %> </ul> <p style="font-family: georgia; font-size: .9em; color:gray; font-style:italic; padding: 5px; margin-top:30px; text-align: center"> give thanks supporting our family of musicians purchase. purchase makes impact on lives of hard working, bluish collar artists. hope enjoy music , can't wait see stories tell. give shout @ <a style="text-decoration: none" href="mailto:compass@marmosetmusic.com" target="_blank"><span style="color:#8a4fab; font-style: normal">compass@marmosetmusic.com</span></a> share masterpiece when it's finished.</p> </div> </body> </html>

edit: if run wkhtmltopdf www.marmosetmusic.com myhomepage.pdf in terminal, works locally, if log bash of heroku app , run this, same error /app/vendor/bundle/ruby/2.0.0/gems/bundler-1.6.3/lib/bundler/rubygems_integration.rb:305:in 'block in replace_bin_path': undefined method 'name' nil:nilclass (nomethoderror) /app/vendor/bundle/bin/wkhtmltopdf:16:in'`

ruby-on-rails-3 heroku bundler production-environment wicked-pdf

No comments:

Post a Comment