Forum: Ruby on Rails use Prawn to generate pdf

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Guoyou J. (Guest)
on 2008-10-26 10:55
(Received via mailing list)
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 L. (Guest)
on 2008-10-26 12:47
(Received via mailing list)
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 J. 
<removed_email_address@domain.invalid>
wrote:
>   private
> '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
Guoyou J. (Guest)
on 2008-10-27 10:38
(Received via mailing list)
Hi, Maricio:
     i had test again, but the result is same, i got a test.pdf file
,but
when i open it, it's blank.

2008/10/26 Maurício Linhares <removed_email_address@domain.invalid>

>  private
>
> >   end
> > map.download '/download', :controller => 'download', :action =>
> > >
>
--
Thanks!
Guoyou
This topic is locked and can not be replied to.