pdfkit的image和print_media_type无法在rails 4.0.2上运行

时间:2014-02-17 12:46:58

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2 ruby-on-rails-3.1

我使用pdfkit创建了一个pdf.Pdf已创建。但是图像没有显示在我的pdf上,print_media_type也无效。我使用的是rails 4.0.2和ruby 2.0.0。有谁可以帮我解决这个问题?我在这里附上细节。谢谢。

宝石文件:

gem 'pdfkit','0.5.2'    
gem 'wkhtmltopdf-binary','0.9.9.1'
gem 'wkhtmltopdf-heroku','1.0.0'

application.css:

@media print {
body {    
    text-align: justify;
    font-size:566px;
    background-color: red;
  }  
}

application.rb中:

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

config / initializers / pdfkit.rb:

PDFKit.configure do |config|
  config.wkhtmltopdf = 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'
  config.default_options = {
    :page_size => 'A4',
    :page_height => '2478',
    :footer_right => "Page [page] of [toPage]",
    :margin_top=>"0.5in",
    :margin_right=>"1in",
    :margin_bottom=>"0.5in",
    :margin_left=>"1in",
    :zoom => '1.5',
    :disable_smart_shrinking=> false,
    :print_media_type => true
  }
  config.root_url = "//localhost" 
end

application.html.erb:

<%= stylesheet_link_tag "application", :media => "all", "data-turbolinks-track" => true %>`
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>`
<body>
  <%= image_tag "rails.png", size: "725x150" %>
</body>

1 个答案:

答案 0 :(得分:0)

使用

<img src="<%=root_url%>/rails.png" height="725" width="150" > 

<img src="<%=root_url%>/assets/rails.png" height="725" width="150" >