pdf_writer_proxy

What is it?

Ruport provides a bunch of shortcuts for common PDF operations. Still, if you have complex reports, you may find yourself creating a pdf_writer.something soup in your formatters.

This plugin DRYs up your PDF formatter by forwarding unhandled requests to pdf_writer.

Installation

gem install pdf_writer_proxy --source http://gems.rubyreports.org

You need at least Ruport 0.11.0 installed to use this plugin.

If you want to de-pluginize this, the sources are available via

  svn co http://stonecode.svnrepository.com/svn/ruport/plugins/pdf_writer_proxy

Example

This contrived example shows the utter absence of pdf_writer calls.

# -- make sure you enable plugins
require "ruport/extensions"

class MyRenderer < Ruport::Renderer
 stage :body
end

class MyFormatter < Ruport::Formatter::PDF

 renders :pdf, :for => MyRenderer

 # -- this is where the magic happens
 proxy_to_pdf_writer

 def build_body
  # PDF::Writer call,mixed with ruport
   start_page_numbering(right_boundary-10,bottom_boundary+5,10,nil,"<PAGENUM>")

   # ruport calls
   pad(20) { add_text "hello world" }
   add_text "mixing ruport with PDF::Writer", :font_size => 14

   start_new_page # PDF::Writer call
   add_text "another page"

   stop_page_numbering # PDF::Writer
   start_new_page
   select_font "Courier"

   add_text "Finally, the last page"
   render_pdf
 end

end

If you really want to get on with your bad self, you can skip out on Ruport's rendering system with a little hackery.

$ irb -Ilib -rubygems
>> require "ruport"  
=> true
>> require "ruport/extensions"
=> true
>> Ruport::Formatter::PDF.proxy_to_pdf_writer
=> Ruport::Formatter::PDF
>> a = Ruport::Formatter::PDF.new
=> #<Ruport::Formatter::PDF:0x147988c>
>> a.options = Ruport::Renderer::Options.new
=> #<Ruport::Renderer::Options>
>> a.add_text "Foo", :font_size => 18
=> 735.192
>> a.save_as("bar.pdf")

Problems?

Please let Gregory know on the mailing list if this does not work as expected.