本文介绍了pdfkit 的图像和 print_media_type 在 rails 4.0.2 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 pdfkit 创建了一个 pdf.创建了 PDF.但是图像没有显示在我的 pdf 上,并且 print_media_type 也不起作用.我正在使用 rails 4.0.2 和 ruby​​ 2.0.0.任何人都可以帮我解决这个问题吗?我在这里附上详细信息.谢谢.

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 '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>

推荐答案

使用

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

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

这篇关于pdfkit 的图像和 print_media_type 在 rails 4.0.2 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 13:21