title: Rendering CSS using PDFKit
body: <p>I know that there have been other questions about this, but I've read through them all and haven't figured this out yet. I'm using the PDFKit gem to allow users to generate .pdfs of content on my site. I can render a pdf by adding .pdf to the url, but CSS doesn't transfer along with it. I understand from Googling that it's because of the asset pipeline, but I haven't figured out how to make it work.</p>
  
  <p>I've installed both of teh necessary gems:</p>
  
  <pre><code>gem 'pdfkit', '~&gt; 0.6.2'
  gem 'wkhtmltopdf-binary' 
  </code></pre>
  
  <p>In my application.rb file I added 'require pdfkit' at the top and the following to the application class:</p>
  
  <pre><code>    config.middleware.use PDFKit::Middleware
  
      config.cache_classes = true
  
      config.eager_load = true
  </code></pre>
  
  <p>I then ran rake middleware</p>
  
  <p>I also added an initializer called pdfkit.rb with teh following code that I found, in order to fix the .pdf from endlessly loading:</p>
  
  <pre><code>ActionController::Base.asset_host = Proc.new { |source, request|
  if request.env["REQUEST_PATH"].include? ".pdf"
   "file://#{Rails.root.join('public')}"
  else
   "#{request.protocol}#{request.host_with_port}"
  end
  }
  </code></pre>
  
  <p>At this point adding .pdf to a url creates the pdf, but doesn't render the CSS at all. The README on pdfkit's github says:</p>
  
  <p>"Resources aren't included in the PDF: Images, CSS, or JavaScript does not seem to be downloading correctly in the PDF. This is due to the fact that wkhtmltopdf does not know where to find those files. Make sure you are using absolute paths (start with forward slash) to your resources."</p>
  
  <p>My CSS is called in the head as usual:</p>
  
  <pre><code>&lt;%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" =&gt; true %&gt;
  </code></pre>
  
  <p>How do I make an absolute path? I don't think I just replace the stylesheet_tag with an ordinary </p>
  
  <pre><code> &lt;link rel='stylesheet' href='bootstrap_and_customization.css.scss' type="text/css"&gt;
  </code></pre>