Image and print_media_type for pdfkit are not working on rails 4.0.2

走远了吗. 提交于 2019-12-24 11:25:06

问题


I have created a pdf using pdfkit.Pdf is created. But the image is not displaying on my pdf and the print_media_type is also not working. I am using rails 4.0.2 and ruby 2.0.0. can anyone please help me to solve this problem? I am attaching details here. Thank you.

gem file:

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:


use

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

or

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


来源:https://stackoverflow.com/questions/21829538/image-and-print-media-type-for-pdfkit-are-not-working-on-rails-4-0-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!