# Export to PDF

**URL:** <https://www.ruby-forum.com/t/export-to-pdf/164248>\
**Category:** Rails\
**Created:** [March 30, 2009, 12:24pm UTC](https://www.ruby-forum.com/t/export-to-pdf/164248 "2009-03-30T12:24:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devirv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de053/32.png) [@devirv](https://www.ruby-forum.com/u/devirv)\
**Post date:** [March 30, 2009, 12:24pm UTC](https://www.ruby-forum.com/t/export-to-pdf/164248/1 "2009-03-30T12:24:43Z")

</div>

Dear All,

How to export a dataset to PDF file. I wrote the following code for  
exporting a dataset to pdf file. I want the column name and column  
seperators(leave space for each column),Please find the attatched file,  
i want to seperate the values as explaned.How the same will be applied  
in NetBeans IDE.

```
         def prints
     @records = Company.find(:all)
         _pdf = PDF::Writer.new
         _pdf.select_font "Times-Roman"
         @records.each do |company|
        _pdf.text company.name + company.com_address1 +
                                  company.com_address2,:border=>'1'

         end
   send_data _pdf.render, :filename => "hello.pdf",
                                :type => "application/pdf"

```

end

AnyOne Knows please let me know.

Regards  
R.Devi

---

<div class="post-metadata">

**Author:** ![devirv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de053/32.png) [@devirv](https://www.ruby-forum.com/u/devirv)\
**Post date:** [March 30, 2009, 4:26pm UTC](https://www.ruby-forum.com/t/export-to-pdf/164248/2 "2009-03-30T16:26:03Z")

</div>

Refer the following link :  
[artima - Creating Printable Documents with Ruby](http://www.artima.com/rubycs/articles/pdf_writer4.html)

---

<div class="post-metadata">

**Author:** ![devirv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de053/32.png) [@devirv](https://www.ruby-forum.com/u/devirv)\
**Post date:** [April 1, 2009, 10:33am UTC](https://www.ruby-forum.com/t/export-to-pdf/164248/3 "2009-04-01T10:33:33Z")

</div>

Devy,

How to export a dataset to PDF file. I wrote the following code for

You may consider switching to the prawn library, to generate your pdr.  
See the railscast (10:04)  
[#153 PDFs with Prawn - RailsCasts](http://railscasts.com/episodes/153-pdfs-with-prawn)  
and its ascii version  
[http://asciicasts.com/episodes/153-pdfs-with-prawn](http://asciicasts.com/episodes/153-pdfs-with-prawn)

There is a short comparison/example of table → pdf with both libraries  
here  
:

[http://groups.google.com/group/pdf-writer/browse\_thread/thread/5bc8de74e1a7d3c5](http://groups.google.com/group/pdf-writer/browse_thread/thread/5bc8de74e1a7d3c5)

Alain R.

---

<div class="post-metadata">

**Author:** ![devirv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de053/32.png) [@devirv](https://www.ruby-forum.com/u/devirv)\
**Post date:** [April 8, 2009, 12:05pm UTC](https://www.ruby-forum.com/t/export-to-pdf/164248/4 "2009-04-08T12:05:09Z")

</div>

Hi Alain

I tried prawn for pdf creation.

1. gem install prawn

2. script/plugin install git://github.com/thorny-sun/prawnto.git

3. In environment.rb file add the line config.gem ‘prawn’

4. i wrote in the following code in “show.pdf.prawn” it’s located  
in(/app/view/orders/show.pdf.prawn) pdf.text “Hello, World!”

5. In my controller is  
def show

6. [http://localhost:3001/orders/show](http://localhost:3001/orders/show)

7. In this aspect where to give the file name?

How to create simple pdf file using prawn library i followed this url  
but can create the simple file this format  
def show  
Prawn::Document.generate “hello-ttf.pdf” do  
fill\_color “0000ff”

text “Hello World”, :at =\> [200,720], :size =\> 32  
text "This is chalkboard wrapping " \* 20  
end  
end

Regards  
R.Devi
