・実現したいこと HTMLをPDFに出力
・問題点 css上のbackground-imageを読み込もうとするとページ読み込みが長時間続き、PDFが出力されない
・環境 Rails 4.2.5
gemに"wicked_pdf"と"wkhtmltopdf-binary"を導入し、pdf出力をしている
html
1コード<!DOCTYPE html> 2<html> 3<head> 4 <title><%= @project.name %></title> 5 <%= wicked_pdf_stylesheet_link_tag "application", media: "all" %> 6 <%= wicked_pdf_stylesheet_link_tag "application" %> 7 <%= wicked_pdf_image_tag "http://localhost:3000/assets/drill.jpg" %> 8</head> 9<body> 10 <div id="box_pdf" style="clear: both;"> 11 </div> 12</body> 13</html>
css
1div#box_pdf{ 2 background-image: url(http://localhost:3000/assets/drill.jpg); 3 position:absolute; 4 width:600px; 5 height:600px; 6 background-position:center top; 7 background-repeat:no-repeat; 8 -moz-background-size:cover; 9 background-size:cover; 10}
ruby
1 def pdf#コントローラー 2 @project = Project.find(params[:project_id]) 3 @project_sheet = Sheet.where("project_id = #{params[:project_id]}") 4 5 6 respond_to do |format| 7 format.html { redirect_to :action => 'detail', :format => 'pdf', debug: 1 } 8 format.pdf do 9 render pdf: @project.name, 10 no_background: false, 11 encording: 'UTF-8', 12 page_height: '260mm', 13 page_width: '320mm', 14 show_as_html: params[:debug].present? 15 end 16 end 17 end
画像の絶対パスは、HTMLで何度か検証したのであっていると思います。
cssのbackground-imageをつけると、上記のように読み込みが延々と続きPDFが出力されないのですが、imageを使わず文字だけの場合はpdfは出力されます。
原因はどこにあるのでしょうか?よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/24 12:57