简体   繁体   中英

CSS not getting applied in wicked_pdf for rails 5

The pdf is generated without any CSS to it. I have used the following code:

In gemfile

gem 'wicked_pdf', '~> 2.1'
gem 'wkhtmltopdf-binary'

in controllers/product_controller - show action


respond_to do |format|
      format.html
      format.pdf do
        render pdf: "product_pdf",
        template: "products/show.html.erb",
        layout: 'pdf.html'
      end
    end

I have made a new file called pdf.html.erb in app/views/layout:

<!DOCTYPE html>
<html>
<head>
<title>PDF</title>
  <%= wicked_pdf_stylesheet_link_tag "styles" -%>
</head>
<body>
  <div class='container'>
    <%= yield %>
  </div>
</body>
</html>

I am rendering it in product/show.html.erb

<p id="pdf_link"><%= link_to "Download Solution", product_path(@product, :format => "pdf") %></p>

Need help with this.

This is what my stylesheet import would look like:

<%= stylesheet_link_tag wicked_pdf_asset_base64 "styles" %>

The styles.scss (or.css) file should be located in the app/assets/stylesheets/ folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM