1.9.2 & rails 3.0.9
wicked_pdf 0.8.0
wkhtmltopdf 0.10.0 rc2 # /usr/local/bin/
nginx and pow
It seems to barely work, if at all, and it's extremely slow when it does. What I've done:
after bundle install, went into rails console for simple test:
pdf = WickedPdf.new.pdf_from_string('Hello There!')
"******\"/usr/local/bin/wkhtmltopdf\" -q - -
******"
which hangs like that for a very long time, like, 30 minutes or so, but eventually comes back.
Dropped to shell to test wkhhtmltopdf directly with wkhtmltopdf google.com google.pdf and that comes back with:
Loading page (1/2)
Printing pages (2/2)
Done
Pretty quick, although I had to cntl-c out
After some digging, I added wkhtmltopdf-binary to gem file, bundle install... same results
My wicked_pdf.rb initializer:
WickedPdf.config = {
:exe_path => '/usr/local/bin/wkhtmltopdf',
:layout => 'pdf.html',
:orientation => 'Landscape',
:page_size => 'Letter'
}
Thanks in advance
It looks like your problem may be related to this issue:
https://github.com/mileszs/wicked_pdf/issues/110
Try rolling back wkhtmltopdf to version 0.9.9 and let me know if you still have issues.
Related
I have been struggling with rerunning my apps from MAC OS to my windows OS. I have never liked databases. Anyway, the thing is that I cannot even load up my seeds. It looks like it cannot run the pg gem methods. Here's my error
:in `ensure in run': undefined method `close' for nil:NilClass (NoMethodError)
here's the code the method gets stuck on
require_relative('../models/collection')
require_relative('../models/product')
require('pry')
Product.delete_all()
Collection.delete_all()
fw2015 = Collection.new({
'name' => 'Fall Winter 2015/2016'
})
fw2015.add()
I am pretty sure that it's something with postgres. Thank you for your help
This is a gem issue, not a PostgreSQL issue. It is probably relating to the fact that there are binary portions of the gem and they may not be building right. So you need to make sure that you have the PostgreSQL client libraries and header files installed, and that you have all necessary compilers.
Try uninstalling and re-installing the gem and see what errors and warnings show up.
I'm using capybara webkit on Ubuntu (14.04 LTS) and I'm getting the following error when trying to use it:
Capybara::Webkit::ConnectionError: /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/bin/webkit_server failed to start.
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:75:in `parse_port'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:81:in `discover_port'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:62:in `start_server'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:25:in `initialize'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/driver.rb:17:in `new'
I installed QT using:
sudo apt-get install libqt4-dev libqtwebkit-dev libqt5webkit5-dev
Using gem versions: capybara (2.4.4) and capybara-webkit (1.3.1)
The same program works fine on mac (qt installed using homebrew)
Thanks
It has been a long time since this question was asked, but I had the same problem even though I used much more ancient versions of anything. It turned out that webkit needs to be able to connect to some X-Server and this is its reaction if it fails. I ended up installing xvfb and using
xvfb-run --auto-servernum bundle exec rake test
(aliased of course) when running my tests. This is probably less than optimal, but it was good enough for me. Maybe this helps the next person who stumbles across this error.
I beat my head against this all morning. Turns out I had omitted this code from rails_helper.rb :
if ENV['HEADLESS']
require 'headless'
headless = Headless.new
headless.start
at_exit { headless.stop }
end
We use the HEADLESS environment variable to trigger this. Not sure if that's typical or a local convention. Regardless, I needed to add export HEADLESS=1 to .env to fire that off.
I also had to add gem 'headless', '~> 1.0.2' in Gemfile.
I am trying to use wicked_pdf in my rails 3 application. I have followed all the tutorials and I am getting this error:
Failed to execute:
"/usr/local/bin/wkhtmltopdf" -q "file:////var/folders/_b/50kywsc97r95gvr9gy9nr6700000gn/T/wicked_pdf20130228-874-a51lgi.html" "/var/folders/_b/50kywsc97r95gvr9gy9nr6700000gn/T/wicked_pdf_generated_file20130228-874-1ihqg74.pdf"
I know that wkhtmltopdf exists in the right place because when I type which wkhtmltopdf I am shown the path above. I also get told it's there when I try to brew install again. Furthermore when I type wkhtmltopdf google.com google.pdf it runs fine.
My controller looks like this:
def show #shows some material
#material = Material.find(params[:id])
respond_to do |format|
format.html
format.pdf do
render :pdf => '#{#material.id}',
:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf'
end
end
end
Any suggestions? Does this seem like a wkhtmltopdf issue or a wicked_pdf issue? I have bundle installed everything and bundle updated everything. I have added the wkhtmltopdf-binary gem (which shouldn't be necessary). It doesn't work on heroku either.
Sounds like there may be a few wkhtmltopdf images out there. If rails is trying to use /usr/local/bin/wkhtmltopdf, try the command /usr/local/bin/wkhtmltopdf from a terminal and see is there are any problems running that one. If you have a few copies around from different gem installs, the one that runs first in your search path may not be the one rails is trying.
Hope it helps
Bob
First validate the location of the binaries
Open a terminal prompt and type
$ which wkhtmltopdf
The return in my machine is
/usr/local/bin/wkhtmltopdf
Validate the binaries are working well
wkhtmltopdf google.com google It must generate a pdf with the google webpage
Create a class in your initializer
Look at my gist
And that's all
I've got 3 Rails 3.2 applications using the gem jquery-ui-themes. jquery-ui-themes uses scss for the image-path helper.
It works great on two of my applications, but the 3rd doesn't seem to compile the scss files in either development or production modes.
IOW, it sends this to the browser
background: #fcfdfd url(image-path("jquery-ui/redmond/ui-bg_inset-hard_100_fcfdfd_1x100.png")) 50% bottom repeat-x;
whereas the two working apps properly send
background: #fcfdfd url("/assets/jquery-ui/redmond/ui-bg_inset-hard_100_fcfdfd_1x100.png") 50% bottom repeat-x;
I've spent many hours trying to make the app that's broken as similar to possible to the two working apps as I can, but it's still failing.
My theory is that SASS is choking on something previous to redmond.css.scss. If so, there should be an error logged somewhere. Where do I find the error output from SASS?
Update:
I introduced a deliberate error into redmond.css.scss and I got a proper error dump. So I know that I'm correctly clearing the cache and actually running sass. Now to figure out why it's ignoring the image-path directives.
If you're looking for the answer to the question in the title, the answer is "the same way you get any other errors: they're in your log". To get a full backtrace, just point your browser at the asset: ie http://localhost:3000/assets/jquery-ui/redmond.css in my case.
Make sure you clear all your caches: rm -rf .sass-cache/ && rm -rf public/assets && rake tmp:cache:clear, as well as using ctrl-shift-r in your browser.
If you're looking for the answer for my real problem (image-path not working), make sure you have the proper Bundler.require line in your application.rb. The old Rails 3.0 doesn't work.
replace:
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
with:
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
Background
After reading around it seemed to me that Prawn is out and wkhtmltopdf is in. It also seems like the PDFKit and wicked_pdf gems for Rails are the new cool. So I found a screencast by Ryan on how to use PDFKit. I installed everything, tested wkhtmltopdf on the CLI with no problems, fiddled around with Rails settingsto run multiple processes so the asset pipeline works, and all seemed good, except I'm still stuck at the very end of the process (actually getting the PDF response from the server).
Question
When I request a .pdf version of my view (I'm using the PDFKit Middleware option) my browser just sits there waiting for a response, but as soon as I kill the Rails process the PDF I expected to get only then pops up in my browser window. What gives?
What I'm Using
OS: OSX 10.8.1
Rails: 3.2.8
Ruby: 1.9.3
wkhtmltopdf: 0.11.0_rc1 (although when I run wkhtmltopdf -V it says 0.10.0_rc2)
qt: 4.8.2
What I've Done
used the PDFKit middleware by loading config.middleware.use "PDFKit::Middleware" in my application.rb file.
included gem 'pdfkit' in my Gemfile and installed it with Bundler
set the .pdf mime-type in my mime_types.rb initializer with Mime::Type.register_alias "application/pdf", :pdf
added config.threadsafe! to config/environments/development.rb for multiple threads so asset pipeline doesn't conflict with PDF engine
tested wkhtmltopdf http://www.google.com google.pdf and it generated a PDF of the Google homepage as expected
tried swapping PDFKit for wicked_pdf and encountered the same problem (hanging, but when Rails process is killed the PDF renders as expected)
What it Looks Like
This is the regular html page rendered by Rails (I've blurred the client details):
This is the CLI output by Rails when I try to navigate to localhost:3000/some/path.pdf. (the app hangs while waiting for a response):
When I finally kill the Rails process with ctrl-c the PDF finally shows up in the browser as I expected to see it (CSS and HTML rendered properly, so assets seem to load fine):
Conclusions So Far
Swapping PDFKit for wicked_pdf and getting the same results seems to make me think the problem isn't with those libraries, but something to do with my development environment. But wkhtmltopdf runs fine off the command line, so that makes me think that it and QT are doing their job. The problem must be in Rails. Maybe I'm not configuring something properly?
Plea for Help
How do I determine what exactly the problem is and how do I fix it?
I'll love you if you can help me <3
Update
I've also tried using an alternative method of rendering the PDF (with .to_pdf) without the middleware option as follows (doing this I commented out config.middleware.use "PDFKit::Middleware" from my application.rb file):
respond_to do |format|
format.html
format.pdf do
html = '<html><body>This is a test.</body></html>'
#pdf = PDFKit.new(html)
send_data #pdf.to_pdf,
:filename => 'whatever.pdf',
:type => 'application/pdf',
:disposition => 'attachment'
end
end
The problem is with wkhtmltopdf itself, specifically, any version after 0.9.9. wkhtmltopdf hangs when run directly from the command-line.
Steps to correct:
brew uninstall wkhtmltopdf
cd /usr/local/Library/Formula/
git checkout 6e2d550 /usr/local/Library/Formula/wkhtmltopdf.rb
brew install wkhtmltopdf
Then verify the correct version is installed wkhtmltopdf --version which should yield wkhtmltopdf 0.9.9
Citations:
https://github.com/mileszs/wicked_pdf/issues/110
http://wearepandr.com/blog/article/homebrew-and-installing-old-package-versions#blog_nav
Try the last version. The easy way install on MacOS:
brew install Caskroom/cask/wkhtmltopdf
The fix by scarver2 worked for me as advertised. But I needed a more recent version of wkhtmltopdf. Since the homebrew version still seems outdated (it still hangs on the command line), and since there isn't a recent precompiled binary available, I used the os x build script to compile one myself:
$ git clone git#github.com:wkhtmltopdf/wkhtmltopdf.git
$ cd wkhtmltopdf
$ ./build_osx.sh # i'm running 10.9.2
$ bin/wkhtmltopdf --version
Name:
wkhtmltopdf 0.12.1-72a9f2066fe9ffd162dec007a4d9b6a5cd63b670
$ curl www.example.com | bin/wkhtmltopdf - test.pdf # render pdf of example.com
$ open test.pdf # to confirm pdf
I'm using pdfkit 0.6.2 with Rails 3.2.17. I put the binary in /vendor and, in a pdfkit initializer, pointed to it with config.wkhtmltopdf. So far, so good.
I got the same issue. It works when I added: 'config.threadsafe!' in application.rb as the answer in the stack. Hope this help.
Mine was also hanging and opening the wkhtmltopdf icon in the dock.
I actually found the problem for me was I only had 1 unicorn worker process running. Once I added more than 1 it worked fine.
I'm running wkhtmltopdf 0.9.9 on OS X with pdfkit 0.6.2
Exact same symptoms but using WickedPdf currently. At this point, I believe the issue lies with wkhtmltopdf as well.
Unfortunately, neither of the recommendations I've been able to find in Stack/Google worked for me. Instead, I needed to combine several suggestions, including some found in this post.
Solution was:
brew uninstall wkhtmltopdf
find and delete any copies of wkhtmltopdf in /usr/bin
comment WickedPdf.config line in config/initializers
add config.threadsafe! to development.rb
remove middleware and allow 'show' action of main controller to handle pdf requests (may not be necessary)
add wkhtmltopdf-binary to gemfile
bundle
restart server
You may also need to add Mime::Type.register_alias "application/pdf", :pdf to config/initializers/mime_types.rb (for me, this causes 'warning: already initialized constant PDF')
My set-up was: Mac OSX Mountain Lion with Rails 3.2.1, Webrick, Postgres and wkhtmltopdf-binary (0.9.9.1).
Try editing config/initializer/pdfkit.rb in the following way:
PDFKit.configure do |config|
config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
config.default_options = {
:encoding=>"UTF-8",
:page_size=>"A4",
:margin_top=>"0.25in",
:margin_right=>"0.1in",
:margin_bottom=>"0.25in",
:margin_left=>"0.1in",
:disable_smart_shrinking=> false
}
end