在Rails 3中无法生成错误PDF [英] Getting error PDF could not generated in Rails 3

查看:105
本文介绍了在Rails 3中无法生成错误PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails 3中使用wicked_pdf gem将HTML文件转换为PDF时,出现以下错误.

I am getting the following error while converting the HTML file to PDF using wicked_pdf gem in Rails 3.

错误:

Error: Failed to execute:
["C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe", "file://C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf20150526-648-17uza61.html", "C:/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf_generated_file20150526-648-w6l9ye.pdf"]
Error: PDF could not be generated!
 Command Error: Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
Error: Failed loading page file://c/DOCUME~1/SUBHRA~1/LOCALS~1/Temp/wicked_pdf20150526-648-17uza61.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentNotFoundError

请检查我下面的代码.

users/index.html.erb:

users/index.html.erb:

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

users/download_pdf.pdf.erb:

users/download_pdf.pdf.erb:

<h1>Hello pdf</h1>

controller/users_controller.rb:

controller/users_controller.rb:

class UsersController < ApplicationController
    def index

    end
    def download_pdf
    respond_to do |format|
        format.pdf{ render pdf: "/users/download_pdf.pdf.erb"}
    end 
    end
end

wicked_pdf.rb:

wicked_pdf.rb:

WickedPdf.config = {
  #:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf',
  #:layout => "pdf.html",
  :exe_path => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'
   #:exe_path => Rails.root.join('bin', 'wkhtmltopdf').to_s
}

宝石文件:

Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.19'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'

我通过从其站点下载安装wkhtmltopdf并在wicked_pdf.rb文件中设置了路径.但是我遇到这种类型的错误.我正在使用Rails 3.2.19版和win-xp.这个问题.

I installed wkhtmltopdf by downloading from its site and set the path in wicked_pdf.rb file.But i am getting this type of error.I am using Rails version 3.2.19 and win-xp.Please help me to resolve this issue.

推荐答案

path/to/gem/wkhtmltopdf/bin中找到wicked_pdf.rb,在第64行中将file://替换为file:///(您可以在

Find wicked_pdf.rb in path/to/gem/wkhtmltopdf/bin, on line 64 replace file:// with file:/// (you can read why at https://github.com/mileszs/wicked_pdf/issues/157). If it still didn't work out rename the file download_pdf.pdf.erb to download.erb. It works fine for me :)

这篇关于在Rails 3中无法生成错误PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆