# Use Prawn to generate pdf

**URL:** <https://www.ruby-forum.com/t/use-prawn-to-generate-pdf/151821>\
**Category:** Rails\
**Created:** [October 26, 2008, 9:55am UTC](https://www.ruby-forum.com/t/use-prawn-to-generate-pdf/151821 "2008-10-26T09:55:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guoyou\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6bbea6/32.png) [@Guoyou\_J](https://www.ruby-forum.com/u/Guoyou_J)\
**Post date:** [October 26, 2008, 9:55am UTC](https://www.ruby-forum.com/t/use-prawn-to-generate-pdf/151821/1 "2008-10-26T09:55:33Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Guoyou\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6bbea6/32.png) [@Guoyou\_J](https://www.ruby-forum.com/u/Guoyou_J)\
**Post date:** [October 27, 2008, 9:38am UTC](https://www.ruby-forum.com/t/use-prawn-to-generate-pdf/151821/2 "2008-10-27T09:38:59Z")

</div>

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](mailto:removed_email_address@domain.invalid)

> private
> 
> > end  
> > map.download ‘/download’, :controller =\> ‘download’, :action =\>
> > 
> > >

–  
Thanks!  
Guoyou

---

<div class="post-metadata">

**Author:** ![Guoyou\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6bbea6/32.png) [@Guoyou\_J](https://www.ruby-forum.com/u/Guoyou_J)\
**Post date:** [October 26, 2008, 11:47am UTC](https://www.ruby-forum.com/t/use-prawn-to-generate-pdf/151821/3 "2008-10-26T11:47:58Z")

</div>

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](mailto:removed_email_address@domain.invalid)  
wrote:

> private  
> ‘download\_pdf’  
> when i type [http://localhost:3000/download](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/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)  
João Pessoa, PB, +55 83 8867-7208
