Rails 中的 PDFKit 给出服务 500 错误

发布于 2024-09-08 19:53:12 字数 1614 浏览 14 评论 0原文

我正在尝试在 Rails 2.3 环境中的 Windows 中使用 pdfkit。然而 pdfkit 的中间件给出了一些错误,导致 Rails 加载服务错误。我该怎么办?有没有易于使用的 PDFkit 替代品?

嗯,我目前正在关注 PDFKit 上的 Rails 截屏视频。我安装了 pdfkit gem ,wkhtmltopdf ,然后将中间件加载到environment.rb文件中 需要“pdfkit” config.middleware.use“PDFKit::中间件” 然后,当我转到任何页面并添加 .pdf 扩展名时,我收到 500 服务器错误

/!\ 故障安全 /!\ 2010 年 7 月 11 日星期日 18:42:53 +0530 状态:500 内部服务器错误 私有方法 chomp' 调用 nil:NilClass C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/whiny_nil.rb:52:inmethod_missing' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/pdfkit.rb:69:in wkhtmltopdf' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/pdfkit.rb:33:in初始化' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/middleware.rb:25:in new' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/middleware.rb:25:in调用' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in call' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in调用' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24:in call' C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in调用'

I am trying to use pdfkit in windows in my rails 2.3 environment. However the middleware that pdfkit gives some error which causes rails to load the service error. What do i do about this? Are there any alternatives to PDFkit which are easy to use ?

Well i am currently following the Rails screencast on PDFKit. I installed the pdfkit gem ,wkhtmltopdf and then loaded the middleware in the environment.rb file as
require 'pdfkit'
config.middleware.use "PDFKit::Middleware"
then when i go to any page and add the .pdf extension i get the 500 server error

/!\ FAILSAFE /!\ Sun Jul 11 18:42:53 +0530 2010
Status: 500 Internal Server Error
private method chomp' called for nil:NilClass
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/whiny_nil.rb:52:in
method_missing'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/pdfkit.rb:69:in wkhtmltopdf'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/pdfkit.rb:33:in
initialize'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/middleware.rb:25:in new'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/pdfkit-0.3.3/lib/pdfkit/middleware.rb:25:in
call'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in call'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in
call'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24:in call'
C:/Program Files/BitNami RubyStack/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in
call'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏大泽ㄣ 2024-09-15 19:53:12

如果您在 Windows 上使用 pdfkit,则需要安装 wkhtmltopdf。之后你需要在你的enviroment.rb上配置wkhtmltopdf,如下所示:D。

PDFKit.configure do |config|
   config.wkhtmltopdf = 'C:\opt\wkhtmltopdf\wkhtmltopdf.exe'
   config.default_options = {
     :page_size => 'Legal',
     :print_media_type => true
   }
   config.root_url = "http://localhost" # Use only if your external hostname is unavailable on the server.
end

我希望这有帮助。

If you are using pdfkit on windows you need to install the wkhtmltopdf. After it you will need to configure the wkhtmltopdf on your enviroment.rb like this :D.

PDFKit.configure do |config|
   config.wkhtmltopdf = 'C:\opt\wkhtmltopdf\wkhtmltopdf.exe'
   config.default_options = {
     :page_size => 'Legal',
     :print_media_type => true
   }
   config.root_url = "http://localhost" # Use only if your external hostname is unavailable on the server.
end

I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文