PDFKit ignoring CSS

20 views
Skip to first unread message

Tony Tambe

unread,
Dec 13, 2014, 10:16:25 AM12/13/14
to rubyonra...@googlegroups.com
I've narrowed down my issue to what I think is the initializer. Basically, when I add ".pdf" to a url I get a CSS styled page on Heroku, but when I add @media print { } it has no effect on the page.

Here is my initializer pdfkit.rb:

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
}

Here is my CSS:

@media print {

  #scores table tr td, #scores table tr th {
    page-break-inside: avoid !important;
  }

  table, tr, td, th, tbody, thead, tfoot {
    page-break-inside: avoid !important;
  } 
}
I think it's not recognizing the .pdf as "print" CSS
Reply all
Reply to author
Forward
0 new messages