簡體   English   中英

使用PDFKit和wkhtmltopdf在rails 4 app中生成pdf

[英]Generating pdf in rails 4 app using PDFKit and wkhtmltopdf

我在rails應用程序上有一個現有的ruby,我想生成特定視圖頁面的pdf。 我在我的系統中安裝了wkhtmltopdf和pdfkit。 我正在使用Windows 8.1 64位版本,我正在關注Ryan Bate的rails for pdfkit教程。 教程鏈接在這里: -

http://railscasts.com/episodes/220-pdfkit?autoplay=true

我的config \\ initializers \\ pdfkit.rb文件如下: -

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

現在,當我要通過在URL末尾附加.pdf打開瀏覽器上的視圖文件時,我收到以下錯誤:

命令失敗(exitstatus = 1):C:\\ RailsInstaller \\ wkhtmltopdf \\ bin \\ wkhtmltopdf.exe --page-size法律--print-media-type - -

例如,我的一篇文章的URL是:

HTTP://本地主機:3000 /用品/ 9

現在當我輸入http:// localhost:3000 / articles / 9.pdf時 ,我收到上述錯誤。

請幫我搞清楚。

提前致謝!!!

您可能需要告訴Rails使用PDFKit中間件。 config\\initializers\\pdfkit.rb文件應如下所示:

PDFKit.configure do |config|
  ...
end

require "pdfkit"
Rails.application.config.middleware.use PDFKit::Middleware, print_media_type: true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM