Open ahanmal opened 9 years ago
It appears this is somehow having trouble reading an asset using open-uri
within wicked_pdf_stylesheet_link_tag
, where it is trying to read in a stylesheet over the internet, eventually leading to https://github.com/mileszs/wicked_pdf/blob/master/lib/wicked_pdf/wicked_pdf_helper.rb#L120
What does that wicked_pdf_stylesheet_link_tag
call look like in your app? Is the stylesheet on a remote host? Does it work with a regular stylesheet_link_tag
?
This is the direct code from my app:
<!doctype html>
<html>
<head>
<meta charset='utf-8' />
<%= wicked_pdf_stylesheet_link_tag "documents-pdf" -%>
</head>
<body>
<div id="pdf-header">
<%= params[:debug].present? ? image_tag('documents/vocabulist_black.jpg') : wicked_pdf_image_tag('documents/vocabulist_black.jpg') %>
<h2 id="pdf-title"><%= @document.title %></h2>
</div>
<div id="pdf-content">
<br>
<br>
<table>
<tbody>
<% @document.words.each do |word| %>
<tr>
<td>
<%= word %>
</td>
<td>
<%= @document.dictionary[word] %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</body>
</html>
The assets are on Cloudfront on the staging server, while on the development server, they are served by rails. That might be the problem. Ideas?
That is very likely the problem. Try using just regular image_tag
instead of wicked_pdf_image_tag
.
Any news regarding this issue? I can't use basic stylesheet_link_tag
helper as it breaks the display.
EDIT: My bad. The error was issued because of a file missing in my manifest.
Hi there, I stay stuck on that issue for days, I really need help. Pdf conversion succeeds on local server but crash on heroku Here are my heroku logs:
ActionView::Template::Error (undefined method `find_asset' for nil:NilClass):
2016-01-22T21:14:53.472646+00:00 app[web.1]: 6: <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
2016-01-22T21:14:53.472647+00:00 app[web.1]: 7: <meta charset='utf-8' />
2016-01-22T21:14:53.472648+00:00 app[web.1]: 8: <%#= stylesheet_link_tag "application", media: 'all' %>
2016-01-22T21:14:53.472666+00:00 app[web.1]: 9: <%= wicked_pdf_stylesheet_link_tag "application", media: 'all' %>
2016-01-22T21:14:53.472667+00:00 app[web.1]: 10: </head>
2016-01-22T21:14:53.472668+00:00 app[web.1]: 11: <body id="pdf_body">
2016-01-22T21:14:53.472668+00:00 app[web.1]: 12:
2016-01-22T21:14:53.472669+00:00 app[web.1]: app/views/bills/show.pdf.erb:9:in `_app_views_bills_show_pdf_erb__2743476161104474535_70162487021800'
My Gemfile:
gem 'wicked_pdf'
gem 'wkhtmltopdf-heroku'
gem 'wkhtmltopdf'
initializers/wicked_pdf.rb:
WickedPdf.config = {
}
I just encountered this same issue as well on Heroku, things work fine locally but the following error is thrown within my demo environment: ActionView::Template::Error: 403 Forbidden
Here is the backtrace
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:353 in open_http
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:724 in buffer_open
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:210 in block in open_loop
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:208 in catch
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:208 in open_loop
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:149 in open_uri
/gems/open_uri_redirections-0.2.1/lib/open-uri/redirections_patch.rb:55 in open_uri
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:704 in open
/app/vendor/ruby-2.1.2/lib/ruby/2.1.0/open-uri.rb:34 in open
/gems/wicked_pdf-1.0.6/lib/wicked_pdf/wicked_pdf_helper/assets.rb:107 in read_from_uri
/gems/wicked_pdf-1.0.6/lib/wicked_pdf/wicked_pdf_helper/assets.rb:96 in read_asset
/gems/wicked_pdf-1.0.6/lib/wicked_pdf/wicked_pdf_helper/assets.rb:17 in block in wicked_pdf_stylesheet_link_tag
/gems/wicked_pdf-1.0.6/lib/wicked_pdf/wicked_pdf_helper/assets.rb:15 in collect
/gems/wicked_pdf-1.0.6/lib/wicked_pdf/wicked_pdf_helper/assets.rb:15 in wicked_pdf_stylesheet_link_tag
My problem vanished with that config:
# Gemfile
gem 'wicked_pdf', github: 'mileszs/wicked_pdf'
gem 'wkhtmltopdf-binary'
# config/initializers/wicked.rb
WickedPdf.config = {}
<!-- page.pdf -->
<%= wicked_pdf_stylesheet_link_tag "application", media: 'all' %>
I was able to overcome my issue by limiting the amount of styles I was loading to the bare essentials for my pdf to render properly, leaving everything else I needed behind. I then started getting a similar issue with wicked_pdf_javascript_include_tag
and again solved it by limiting JS to the bare essentials and loading everything I could from CDNs with the regular javascript_include_tag instead of using local files. Works for now.
We had the same problem and fixed changing:
<%= wicked_pdf_stylesheet_link_tag "documents-pdf" -%> for this <%= stylesheet_link_tag(wicked_pdf_asset_base64('documents-pdf')) -%>
Thanks @zerobatu, it helped me a lot. I would appreciate even more if you could say a little about why this alternative solved the problem, I guess it is about on how wicked_pdf request the resource but it is a guess though.
Everything was working fine on my Local and on my Heroku dev environment. Pushed to staging, and now I'm getting this error: ActionView::Template::Error: 403 Forbidden. Emptied the remote repo and repushed - same error.
Here is the stack trace: