2013-12-11 32 views
3

我有一個Rails應用程序,我使用wicked_pdf來生成PDF。這一切都很好,可以在本地工作,但是當推送到heroku時,PDF會呈現,但不會應用樣式表。Wicked_pdf樣式表不能在Heroku上工作

特別是對於PDF渲染,我有一個CSS文件:app/assets/stylesheets/pdf.css.scss。而在form.pdf.haml我加載樣式表是這樣的:

!!! 
    %html{lang: "en", "xml:lang" => "en", xmlns: "http://www.w3.org/1999/xhtml"} 
    %head 
     %meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ 
     = wicked_pdf_stylesheet_link_tag "pdf" 

至於說,它的偉大工程在當地,但是當被推到Heroku的,我得到這個錯誤:

ActionView::Template::Error (No such file or directory - /app/public/pdf.css) 

我有什麼做的在heroku上做這項工作?

編輯:我發現這個Gihub回購https://github.com/jordan-brough/heroku-pdf,這是一個在heroku上使用wicked_pdf的示例應用程序。這實際上有助於在請求PDF時使environment.rb服務於public文件夾中的css文件。

回答

-1

有一個gkh的wkhtmltopdf二進制文件在heroku上工作,而無需在自己的存儲庫中安裝任何二進制文件。它還包含了用於開發的OSX(達爾文)二進制文件。它曾與PDFKit,而且也應該與WickedPDF工作以及

https://github.com/bradphelan/wkhtmltopdf-heroku 

    or in your Gemfile as 
    gem "wkhtmltopdf-heroku" 
+0

二進制文件不是這裏的問題,它呈現PDF很好,只有沒有CSS文件。這個寶石只添加二進制。 – John

0

我試圖this解決方案和wicked_pdf作品。但評論:

"Activating runtime compilation is not the solution, because of the performance hit we take" @David Tuite

,並與non-stupid-digest-assets寶石this評論中發現答案,完美的作品。

3

我有一個類似的問題,並花了我一段時間來破解。我結束了使用wkhtmltopdf-heroku寶石和下面的設置,其中在本地和在Heroku上除了調試選項的正確處理工程:

控制器

respond_to do |format| 
    format.html 
    format.pdf do 
    render pdf: @profile.name + Date.today.to_s(:number), 
      background: true, 
      encoding: 'utf8', 
      :show_as_html => params[:debug].present? 
    end 
end 

show.pdf。 ERB

<% if params[:debug].present? %> 
    <%= stylesheet_link_tag 'documents' %> 
<% else %> 
    <%= wicked_pdf_stylesheet_link_tag 'documents' %> 
<% end %> 
... rest of view ... 

配置/環境/ production.rb

config.assets.precompile += ['documents.css.scss.erb'] 

配置/初始化/ assets.rb

Rails.application.config.assets.precompile += %w(documents.css) 

希望這會有所幫助的人。

+0

非常感謝!這爲我修好了。 – mikewagz

+0

謝謝。這爲我修好了! – Herm