Wednesday, September 12, 2012

Quick Solutions: Rails 3, send_data, and garbled PDF output

This is just a quick blog entry to help anyone experiencing garbled PDF output (in Safari) when using Rails 3's send_data to output dynamically-generated PDF files. 

If you are following the documentation, then you are probably outputting something like this:

    send_data data, :filename => "myfile.pdf",
                          :type => 'application/pdf'

I don't know if this is specific to Rails 3, but the issue is that the Content-Type header is not being set to 'application/pdf', so setting it explicitly in the response should fix this issue:


    response.headers["Content-Type"]='application/pdf'
    send_data data, :filename => "myfile.pdf",
                          :type => 'application/pdf'

2 comments:

  1. Hi. This service here allows you to easily edit your PDF documents.
    http://goo.gl/PQEilT

    You can fill out PDF form, save it, fax it, and email it.

    ReplyDelete
  2. Hey J,
    thank you so much for that great hint! Had the same problem (with rails 4 and firefox) which is now solved.

    ReplyDelete