使用Prawn gem和Ruby on Rails压缩多个PDF

时间:2019-06-12 10:27:03

标签: ruby-on-rails pdf zip prawn

我正在尝试生成一个包含多个pdf的zip文件,我的代码以某种方式生成了zip和pdf,但是当我检查pdf时,每个pdf都已损坏。我不确定自己做错了什么。有帮助吗?

@invoices = Invoice.all
stringio = Zip::OutputStream.write_buffer do |zio|
  @invoices.each do |invoice|

   invoice_pdf = InvoicePdf.new(invoice)
   invoice_pdf = invoice_pdf.render type: "application/pdf", 
   disposition: "inline", filename: "#{invoice.title}"

   zio.put_next_entry("#{invoice.number}.pdf")
   zio << invoice_pdf
  end
 end

 stringio.rewind

 binary_data = stringio.sysread

 send_data(binary_data, :type => 'application/zip', :filename => 
 "invoice.zip")

0 个答案:

没有答案