0

I am generating a pdf file using WickedPdf.new.pdf_from_string. File itself generates fine, when saved in disk and opened.

But when same file sent via send_data, browser downloads file with pages as per generated file but without any text/content in it. All pages are blank. Here is code snippet

send_data File.open(pdf_file.path, 'rb').read, type: 'application/pdf', filename: 'abc.pdf'

I have also tried send_file without any success.

Environment vars

Rails Version: 4.2.8
Ruby Version: 2.3.3
WickedPdf Ver: 1.1.0
ducktyped
  • 4,354
  • 4
  • 26
  • 38

1 Answers1

1

I wasn't able to reproduce your issue in the wicked_pdf_issues project in this commit

This code downloads and displays just fine:

respond_to do |format|
  format.pdf do
    pdf = WickedPdf.new.pdf_from_string('<html><head><title>foo</title></head><body><h1>This is a PDF</h1></body></html>')
    Tempfile.create do |t|
      t.binmode
      t.write(pdf)
      t.rewind
      t.close
      send_data File.open(t.path, 'rb').read, type: 'application/pdf', filename: 'abc.pdf'
    end
  end
end

You can see the result by going here and clicking the download PDF link.

Unixmonkey
  • 18,485
  • 7
  • 55
  • 78