wicked_pdf_stylesheet_pack_tag doesn't work code example

Example: wicked_pdf_stylesheet_pack_tag doesn't work

# for more details, read the article from 
# https://stackoverflow.com/questions/58490299/how-to-include-css-stylesheet-into-wicked-pdf

# create pdf_helper.rb in app/helpers and add the following code :
module PdfHelper
  def pdf_stylesheet_pack_tag(source)
    if running_in_development?
      options = { media: "all" }
      wds = Webpacker.dev_server
      options[:host] = "#{wds.host}:#{wds.port}" unless show_as_html?
      stylesheet_pack_tag(source, options)
    else
      wicked_pdf_stylesheet_pack_tag(source)
    end
  end

  def pdf_javascript_pack_tag(source)
    if running_in_development?
      options = {}
      wds = Webpacker.dev_server
      options[:host] = "#{wds.host}:#{wds.port}" unless show_as_html?
      javascript_pack_tag(source, options)
    else
      wicked_pdf_javascript_pack_tag(source)
    end
  end
  
  def show_as_html?
    params[:debug].present?
  end
end

# Then, in the pdf layout (slim)

html
  head
    ...
    = pdf_stylesheet_pack_tag "pdf"
    = pdf_javascript_pack_tag "pdf"
    ...

Tags:

Misc Example