0
rails
アプリケーションでwicked_pdf
gemを使用してpdf
を生成しようとしています。私は私のファイルに次のコードを持っています。 /config/initializers/mime_types.rb
wicked_pdf gemでpdfを作成することができませんでしたか?
Mime::Type.register "application/xls", :xls
Mime::Type.register "application/xlsx", :xlsx
Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf)
とファイルviews/invoises/show.pdf.erb
0内で
gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
とConfig /イニシャライザ/ wicked_pdf.rbファイル内
WickedPdf.config = {
# Path to the wkhtmltopdf executable: This usually isn't needed if using
# one of the wkhtmltopdf-binary family of gems.
# exe_path: '/usr/local/bin/wkhtmltopdf',
# or
# exe_path: Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
# Layout file to be used for all PDFs
# (but can be overridden in `render :pdf` calls)
# layout: 'pdf.html',
}
module WickedPdfHelper
if Rails.env.development?
if RbConfig::CONFIG['host_os'] =~ /linux/
executable = RbConfig::CONFIG['host_cpu'] == 'x86_64' ?
'wkhtmltopdf_linux_x64' : 'wkhtmltopdf_linux_386'
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
executable = 'wkhtmltopdf_darwin_386'
else
raise 'Invalid platform. Must be running linux or intel-based Mac OS.'
end
WickedPdf.config = { exe_path:
"#{Gem.bin_path('wkhtmltopdf-binary').match(/(.+)\/.+/).captures.first}/#{executable}"
}
end
end
コントローラで
def show
respond_to do |format|
format.html
format.pdf do
render pdf: "file_name" # Excluding ".pdf" extension.
end
end
end
<p>
Invoice No:
<%= @invoise.invoice_no %>
</p>
<p>
Due date:
<%= @invoise.due_date %>
</p>
<p>
Total Amount:
<%= @invoise.total_amount %>
</p>
と私はブラウザ内でクリックしていたURLは、PDFファイルを生成することができませんでし/invoises/BRUqWOeEVNSN6GCwxQqLGg%253D%253D.pdf
IAMのです。そして、私も何かエラーを取得していません。上記のURLをクリックすると、私のウェブページは読み込みを続けます。私は出力を得ていません。
あなたがこの方法(例 RailsCastsシリーズに基づいて)で行うことができます