Reputation: 1086
I'm not sure what i'm missing, but my css doesn't seem to be working along side wicked_pdf. I have an image linked in my file, which works, but the styles are missing.
Gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
Controller
format.pdf do
render pdf: "day_report",
template: 'day/day_report',
page_size: 'A4'
end
application.html.erb
<head>
<title>Page Title</title>
<%= wicked_pdf_stylesheet_link_tag "styles" %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
day_report.pdf.erb
<%= wicked_pdf_image_tag( 'logo.jpg', height: '100', width: '100') %>
<div class="page-header">
Day Report
</div>
styles.css
.page-header {
padding: 40px 0;
background-color: red;
text-color: #fff;
}
Upvotes: 6
Views: 8808
Reputation: 773
Create a different layout for pdf as below. e.g pdf.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Page title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track':
'reload' %>
<%= wicked_pdf_stylesheet_link_tag "styles" %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'%>
</head>
<body>
<%= yield %>
</body>
</html>
Change controller action as:
format.pdf do
layout:'pdf.html',
render pdf: "day_report",
template: 'day/day_report',
page_size: 'A4',
encoding:"UTF-8"
end
Change styles.css to styles.scss and add it assets.rb.
Rails.application.config.assets.precompile += %w(styles.scss)
Hope this will help.
Cheers
Upvotes: 9
Reputation: 81
Can you please rename styles.css
to styles.css.scss
and add this file to precomiple list Rails.application.config.assets.precompile += %w(styles.css)
and try.
Upvotes: 2