質問

Rails 3アプリでPDFKITをミドルウェアとして使用しようとしています。

コマンドラインからwkhtmltopdfを正常に使用できますが、私のアプリは私にこのエラーを投げ続けています

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" "-" "-"

ターミナルでこれを実行すると、入力を待つので、HTMLを入力してからCtrl-Dを押すと、PDFのように見えるものを吐き出します...しかし、Railsには運がありません。

これが私が持っているものです:

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

私のコントローラー(ファーストライン)

respond_to :html, :pdf

GithubとGoogle、GithubとGoogleですべてのスレッドを経験したと思いますが、運はありません。

誰かが私を正しい方向に助けたり指したりできますか?

ありがとう、P。

役に立ちましたか?

解決

誰かが問題を解決しました 親切に彼らのソリューションを投稿しました.

他のヒント

パスを実行してコピーします

どのwkhtmltopdf

作成 config/initializers/pdfkit.rb:

 PDFKit.configure do |config|
   config.wkhtmltopdf = '/path/to/wkhtmltopdf'
 end

wkhtmltopdf それは宝石が非常に古いので来ます。この宝石をアンインストールして、以下を試してください wkhtmltopdfバイナリファイル. 。ダウンロード、解凍して移動します /usr/local/bin/. 。それは助けになるはずです。

エラーが始まるのはなぜですか

/Users/bobby/... 
それでも、あなたの構成は始まります
/Users/pierrelapree/... 

編集:

あなたのコードとreadmeの例の別の違い: https://github.com/pdfkit/pdfkit 彼らが示すことです config.middleware.use 文字列ではなく、クラスまたはモジュールの引数を取得します。

これを変更してみてください

config.middleware.use "PDFKit::Middleware", :print_media_type => true

これに

config.middleware.use PDFKit::Middleware, :print_media_type => true
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top