views:

617

answers:

3

I just learn Ruby, and i wonder how to generate Reports and Invoices (with Logo, adressfield, footer, variable number of invoice-items (sometimes resulting in more than one page), carry over of the amount to pay from one page to the next, free-floating 2-column text (left-and-right-justified) below the resulting cash-informations).

Currently i get a canvas to print and draw on from the OperatingSystem (matching the printer specifications) and use some draw-, move-, line-, text- and formfeed-API-Functions and do some heavy calculations for textblock-moving (a bit TeX-like).

How will this be done in Ruby?

Building an .odt and throw it to OpenOffice or a .tex and throw it to LaTeX?

Or are there any free Libraries, thet do all this kind of things for me, so i only have to feed the relevant parts, and let Ruby do the Text-Formatting thing?

Thanks for any help that puts me on the right tracks.

Peter

EDIT:

to be more specific: i want to put a corporation logo on the first page (DIN-A4-format, but may also be letter) on a specific position, also the footer on every page and the adress-box on the first page. all the rest should be free floating text blocks with left-right-justification, bold words in the middle of texts.

something like

pdf.column.blocktext("Hello Mr. P\nwe have [b]good news[/b] for you. bla bla bla and so on. Please keep this text together (no page break)...");
pdf.column.floatingblock("This is another block, that should be printed, and can be broken over more than one column...");

which should render the text in the corporate font on the paper, justified, and wrapping neatly to the next column/page if it reaches the bottom of the page.

Thinking about it, this is exactly, what LaTeX is for.

Thanks for help

+3  A: 

I suggest you consider PDF generation. In Rails, it's pretty simple with the Prawn library.

There is also a fresh new Railcast about that.

Official web site.

baijiu
thanks, that may be the right way, just i do not see the Block-Texting-functionality (like justification (Blocksatz)), but i will take some further looks
Peter Miehle
Yeah, it's better now, thanks Jim
baijiu
+4  A: 

You could also check out HtmlDoc for generating PDFs, it just takes in HTML and generates a PDF from it. This approach is nice because it lets you very easily reuse a partial for an on-screen and hard copy invoice.

http://blog.adsdevshop.com/2007/11/20/easy-pdf-generation-with-ruby-rails-and-htmldoc/

fluid_chelsea
not exactly what i need, but also a good starting point.
Peter Miehle
+1  A: 

The Ruport library (Ruby Reports) makes it pretty easy to spit report tables out in multiple formats, including PDF. There's also a ActiveRecord hook acts_as_reportable that gives your models a reporting interface.

Sam C