Here's how you should do it:

class DownloadController < ApplicationController

  def download_pdf
    send_data(generate_pdf, :filename => 'test.pdf', :type => 'application/pdf')
  end

  private
  def generate_pdf
    document = Prawn::Document.new do |p|
      p.text 'Document Name', :align => 'center'
      p.text 'Address: address'
      p.text 'text end'
    end.render
    send_data document, :type => 'application/pdf'
  end
end


On Sun, Oct 26, 2008 at 1:31 AM, Guoyou Jiang <[EMAIL PROTECTED]> wrote:
> Hello:
>     when i use Prawn to generate pdf file for download, i got a blank pdf
> file, can someone tell me why?
>
> require 'prawn'
> class DownloadController < ApplicationController
>   def download_pdf
>     send_data(generate_pdf, :filename => 'test.pdf', :type =>
> 'application/pdf')
>   end
>   private
>   def generate_pdf
>     Prawn::Document.new do |p|
>       p.text 'Document Name', :align => 'center'
>       p.text 'Address: address'
>       p.text 'text end'
>     end.render
>   end
> end
> routes.rb:
> map.download '/download', :controller => 'download', :action =>
> 'download_pdf'
> when i  type http://localhost:3000/download in firefox, i got a blank pdf
> file, no one text in this file why?
> my client adobe reader version 9.0
>
> --
> Thanks!
> Guoyou
>
> >
>



-- 
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en)
João Pessoa, PB, +55 83 8867-7208

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to