I'm trying to print a PDF of my view by using the `'wicked_pdf' gem. This is the first time I use this gem. I've read the the documentation and googled around and I also found some simular questions here on Stack Overflow But nothing seems to do the trick.
I've validated the binaries ( see edit below) they are working fine, so the problem isn´t there.
I found two strange lines in the terminal when running rails s
( See edit at the bottom)
I've been searching for a solution to this for three straight days, and can't figure this out.
Am I missing something here?
the server constantly hangs with that output in the terminal
Rendered pages/partials/_travel_part.html.erb (36.6ms)
Rendered users/show.html.erb within layouts/application (531.7ms)
Rendered layouts/_navbar.html.erb (2.6ms)
Rendered shared/_footer.html.erb (0.8ms)
Completed 200 OK in 1640ms (Views: 1115.4ms | ActiveRecord: 136.0ms)
"***************[\"/usr/local/bin/wkhtmltopdf\", \"-q\", \"file:////var/folders/sm/zwm8cy0x73qb6q1pq22r4bjh0000gn/T/wicked_pdf20160913-35465-hkw9b8.html\", \"/var/folders/sm/zwm8cy0x73qb6q1pq22r4bjh0000gn/T/wicked_pdf_generated_file20160913-35465-10go9dt.pdf\"]***************"
Below is what I have so far.
I want to print views/users/show.html.erb
so in the users_controller.rb
I have this code in the show
method
def show
@user = User.find(params[:id])
@users = User.order('created_at DESC').paginate(page: params[:page], per_page: 30)
@paper = current_user.papers.build
@electro = current_user.electros.build
@hwater = current_user.hwaters.build
@cleaning = current_user.cleanings.build
@transport = current_user.transports.build
@papers = current_user.papers
respond_to do |format|
format.html {render layout:'application'}
format.pdf {render pdf:"test",javascript_delay:2000,
layout:'application',template:'users/show.pdf.erb'}
end
end
In the application.html.erb
I have this in the head
using the wicked pdf helper
<%= wicked_pdf_stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= wicked_pdf_javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= javascript_include_tag "http://www.google.com/jsapi"%>
<%= wicked_pdf_javascript_include_tag 'chartkick'%>
<%= csrf_meta_tags %>
The button in the views/users/show.html.erb
is
<%= link_to 'Download Pdf', user_path(current_user, format: :pdf) %>
in the config/initializers/mime_types.rb
I have this code
Mime::Type.register "application/pdf", :pdf
in the config/initializers/wicked_pdf.rb
I have this code
WickedPdf.config = {
#:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
#:layout => "pdf.html",
:exe_path => '/usr/local/bin/wkhtmltopdf'
}
And in the gemfile.rb
I have those two gems:
gem 'wicked_pdf', '~> 1.0', '>= 1.0.6'
gem 'wkhtmltopdf-binary-edge'
EDIT*
Ok I've Validated the binaries are working fine by typing this wkhtmltopdf google.com google
in the terminal. So my conclusion is that the problem lies somewhere else than in the wkhtmltopdf
. But where? I still can't find out...
(AddingWickedPdf) $ wkhtmltopdf google.com google
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done
(AddingWickedPdf) $
ANOTHER EDIT
I noticed this lines in the terminal when I started my server rails s
earlier to night, I don´t know what it means, but I'm sure it has something to do with the App hanging when rendering pdf:
/Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/http/mime_type.rb:163: warning: already initialized constant Mime::PDF
/Users/dadi/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/actionpack- 4.2.5/lib/action_dispatch/http/mime_type.rb:163: warning: previous definition of PDF was here
It would be so great if someone could take a look at this and guide me to the right path here.
thanks in advance DH
The answer was originally posted here:
How rails resolve multi-requests at the same time?
Subsequently adapted for this question here (Last answer):