使用Rails 3获取Exec格式错误

时间:2015-05-26 09:43:21

标签: ruby ruby-on-rails-3.2 pdfkit

尝试在Rails 3中实现pdfkit gem时出现以下错误。

错误:

Errno::ENOEXEC in UsersController#download_pdf

Exec format error - C:/Site/generate3/bin/wkhtmltopdf-i386 --encoding UTF-8 --page-size A4 --margin-top 0.25in --margin-right 0.1in --margin-bottom 0.25in --margin-left 0.1in --quiet - -
Rails.root: C:/Site/generate3

Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:8:in `download_pdf'

以下是我的代码文件。

  

用户/ index.html.erb:

<p>
    <%= link_to "Download pdf",download_pdf_path(:format => 'pdf') %>
</p>
  

用户/ download_pdf.html.erb

<h1>Hello PDF</h1>
  

控制器/ users_controller.rb:

class UsersController < ApplicationController
    def index

    end
    def download_pdf
        html = render_to_string(:action => "download_pdf.html.erb")
       kit = PDFKit.new(html)
       send_data(kit.to_pdf, :filename => 'report.pdf', :type => 'application/pdf', :disposition => 'inline')

    end
end
  

pdfkit.rb:

PDFKit.configure do |config|

  if ["development"].include?(Rails.env)
    #only if your are working on 32bit machine
    config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
  else
    #if your site is hosted on heroku or any other hosting server which is 64bit
    config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
  end

  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
  

的Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.19'



gem 'sqlite3'



group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'



  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'



gem 'pdfkit', '~> 0.5.3'

请帮我解决这个错误。还让我知道如何在小尺寸的不同窗口中从HTML转换后打开此PDF。我在我的系统中使用Rails 3.2.19和windows xp。

1 个答案:

答案 0 :(得分:0)

试试这个: config.wkhtmltopdf = Rails.root.join(&#39; bin&#39;,&#39; wkhtmltopdf&#39;)。to_s