簡體   English   中英

Ruby on rails wkhtmltopdf css樣式表不能在生產(linux)服務器上呈現

[英]Ruby on rails wkhtmltopdf css style sheets not rendering on production (linux) server

在本地開發環境(windows)中,已成功生成Css樣式的pdf。 但是在托管linux服務器環境時生成的pdf沒有應用css styles.Below是我的wkhtmltopdf(WickedPdf)配置

WickedPdf.config = {
#:wkhtmltopdf => "#{RAILS_ROOT}/pdfbin/wkhtmltopdf-amd64",
:exe_path => "/home/software/.gems/bin/wkhtmltopdf",
:layout => "layouts/pdf.html.erb",
:margin => {    :top=> 40,
                :bottom => 20,
                :left=> 30,
                :right => 30},
:header => {:html => { :template=> 'layouts/pdf_header.html.erb'}},
:footer => {:html => { :template=> 'layouts/pdf_footer.html.erb'}}
#:exe_path => '/usr/bin/wkhtmltopdf'

}

了解更多信息:

這是我的dir結構我在linux rails托管app \\ views \\ layouts,在布局中我有pdf.html.erb,pdf_footer.html.erb,pdf_header.html.erb上面的東西在我的本地windows開發環境中完美運行,但在生產pdf生成沒有樣式。所以請幫助我生成CSS樣式的CSS

應用程序/視圖/布局/ pdf.html.erb

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="<%= (rtl?) ? 'rtl' : 'ltr' %>">
  <head>
    <% @direction = (rtl?) ? 'rtl/' : '' %>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <%= stylesheet_link_tag([@direction+'application', @direction+'_styles/ui.all'])%>
    <%= stylesheet_link_tag(*get_stylesheets) %>
    <%= stylesheet_link_tag  @direction+"_layouts/pdf" %>
    <link rel="stylesheet" type="text/css" href="<%="#{RAILS_ROOT}/public/stylesheets/#{@direction}_layouts/pdf.css" %>" media="all" />
    <link rel="stylesheet" type="text/css" href="<%="#{RAILS_ROOT}/public/stylesheets/#{get_stylesheets}.css"%>" media="all" />
    <link rel="stylesheet" type="text/css" href="<%= "#{RAILS_ROOT}/public/stylesheets/#{@direction}_styles/ui.all.css"%>" media="all" />


  </head>
  <body>

    <%= yield %>

  </body>
</html>

pdf.html.erb包含用於呈現pdf的所有樣式信息,在托管環境中,這些樣式不是由wkhtmltopdf獲取的。 所以伙計們請幫助我

當我在Heroku上部署我的應用程序時,我遇到了與PDFKit類似的問題。 現在,它工作正常(我已將二進制文件包含在項目中)。

在我的布局中:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Page title</title>
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <%= csrf_meta_tags %>
  <style type="text/css" media="all">
    <%= Rails.application.assets['my_css'].to_s.gsub(/\/assets/,"#{root_url}assets") %>
  </style>
</head>
<body>
  <%= yield %>
</body>
</html>

在初始化器中:

# config/initializers/pdfkit.rb
PDFKit.configure do |config|
  if Rails.env.staging? || Rails.env.production?
    config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
  else
    config.wkhtmltopdf = '/Users/my_user_name/.rvm/gems/ruby-1.9.2-p0@my_project/bin/wkhtmltopdf'
  end
  config.default_options = {
    :page_size => 'A4',
    :margin_top => '0in',
    :margin_right => '0in',
    :margin_bottom => '0in',
    :margin_left => '0in',
    :orientation => 'Portrait'
  }
  # Use only if your external hostname is unavailable on the server.
  config.root_url = "http://localhost:3000" unless Rails.env.staging? || Rails.env.production?
end

也許這可以幫助你...或其他人......

暫無
暫無

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

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