Die Schienen PDFKit Befehl fehlgeschlagen
-
10-10-2019 - |
Frage
Ich versuche PDFKit als Middleware zu verwenden, in einer Rails 3 App.
kann ich wkhtmltopdf über die Befehlszeile verwenden, ganz gut, aber mein app hält mir diesen Fehler zu werfen
command failed: "/Users/bobby/.rvm/gems/ruby-1.9.2-p0/bin/wkhtmltopdf" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-right" "0.75in" "--margin-bottom" "0.75in" "--margin-left" "0.75in" "--encoding" "UTF-8" "--print-media-type" "--quiet" "-" "-"
Wenn ich das im Terminal laufen, es wartet auf meine Eingabe, so dass ich einige HTML-Typ, und drücken Sie Ctrl-d und es spuckt, was einige PDF zu sein scheint ... aber kein Glück in Schienen.
Hier ist, was ich habe:
application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require 'pdfkit'
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Mpr
class Application < Rails::Application
YEARS_ARRAY = (2006..2012).map {|y| [y,y]}.unshift(["Year",nil])
MONTHS_ARRAY = (1..12).map{|m| [ Date::MONTHNAMES[m], m]}.unshift(["All months",nil])
config.middleware.use "PDFKit::Middleware", :print_media_type => true
PDFKit.configure do |config|
config.wkhtmltopdf = '/Users/bobby/.rvm/gems/ruby-1.9.2-p0/bin/wkhtmltopdf'
end
end
end
in meinem Controller (erste Zeile)
respond_to :html, :pdf
Ich glaube, ich habe durch alle Threads auf SO, Github und Google gegangen, aber kein Glück.
Kann mir jemand helfen oder Punkt mich in die richtige Richtung?
Danke, P.
Lösung
Someone solved the problem and kindly posted their solution.
Andere Tipps
Run and copy the path
which wkhtmltopdf
Create config/initializers/pdfkit.rb
:
PDFKit.configure do |config|
config.wkhtmltopdf = '/path/to/wkhtmltopdf'
end
The wkhtmltopdf
that comes as a gem is quite old. Uninstall this gem and try to the following wkhtmltopdf binary file. Download, unzip and move it to /usr/local/bin/
. It should help.
Why does the error start with
/Users/bobby/...yet your config starts with
/Users/pierrelapree/...
Edit:
Another difference between your code and the example in the README: https://github.com/pdfkit/PDFKit is that they show config.middleware.use
taking a class or module argument, not a string.
Try changing this
config.middleware.use "PDFKit::Middleware", :print_media_type => true
to this
config.middleware.use PDFKit::Middleware, :print_media_type => true