Prawn vs. PDF::Writer comparison

97 views
Skip to first unread message

Gregory Brown

unread,
Jun 25, 2008, 7:12:56 PM6/25/08
to pdf-w...@googlegroups.com
Hi folks,

Although this is blatent soliciting, I think you're going to like what
you see here.

The attached image shows two PDF tables, the one on the left side
generated by PDF::Writer, the one on the right generated by my
work-in-progress PDF library, Prawn. As you can see, their output is
not that much different, except for a difference of opinion on the
default look for headers.

The difference is in speed and code.

On my machine, to process an 1833 record table took 3.39s, whereas
PDF::Writer took 134.16s.
Prawn scales linearly, so you can expect double the amount of records
to take a little under 7s.

Below are code samples for each library:

== PDF::Writer ==

pdf = PDF::Writer.new
pdf.select_font("Helvetica")

table = PDF::SimpleTable.new do |tab|
tab.column_order.push(*%w(date rate))

tab.columns["date"] = PDF::SimpleTable::Column.new("date") { |col|
col.heading = "Date"
}
tab.columns["rate"] = PDF::SimpleTable::Column.new("rate") { |col|
col.heading = "Rate"
}

tab.orientation = :center
tab.shade_rows = :none

data = csv_data.map do |e|
{ "date" => e[0], "rate" => e[1] }
end

tab.data.replace data
end

table.render_on(pdf)
pdf.save_as('currency_pdf_writer.pdf')

== Prawn ==

doc = Prawn::Document.new

doc.table(csv_data, :font_size => 10,
:vertical_padding => 2,
:horizontal_padding => 5,
:position => :center,
:row_colors => ["ffffff","cccccc"],
:headers => ["Date","Rate"])
doc.render_file('currency_prawn.pdf')

----------------------------------------

Keep in mind that currently, PDF::Writer is being used all over the
place in production. Prawn is *not* ready for production just yet.
But what I would love to see is is the support of PDF::Writer users to
help make Prawn good enough to replace PDF::Writer as soon as we can
stabilize it.

If you're interested in helping test or develop on Prawn, please watch
it on github:

http://github.com/sandal/prawn

You can also get in touch about bug reports, feature requests, or
other questions via our mailing list:

http://groups.google.com/group/prawn-ruby

If you're an IRC user, there are usually some folks lurking in #prawn
on Freenode as well.

So, I won't regularly fill this list with Prawn noise, but I hope you
all find this interesting. :)

-greg

prawn_pdf_writer.png
Reply all
Reply to author
Forward
0 new messages