PDF::Writer for Ruby
26/Feb 2007
This brief blog post is in response to the many emails you wrote to me, to blog a bit about PDF::Writer for Ruby.
PDF::Writer for Ruby by Austin Ziegler, provides the ability to create PDF documents using only native Ruby libraries. Many web applications may want to offer PDF as one possible download format.
If you need to convert PDF to Word in order to more easily edit your PDF files then a specialized piece of PDF converter software is probably better than free online ones.
On your Windows, load the pdf-writer gem and write a PDF. If you don’t already have pdf-writer on your system, just run the following command:
gem install pdf-writer
Now you can use the gem mechanism to load pdf-writer and create a PDF document, as shown in the following example:
require 'rubygems'
require_gem 'pdf-writer'
pdf = PDF::Writer.new
pdf.select_font "Times-Roman"
pdf.text "Hello, Ruby." , :font_size => 72, :justification => :center
pdf.save_as("hello.pdf" )
The call to require ‘rubygems’ loads the gem mechanism, and then the call require_gem ‘pdf-writer’ loads the pdf-writer gem.
The above example is adapted from the tutorial/article on how to publish printable documents at artima.com. In this article, Austin Ziegler introduces the creation of a variety of types of documents with PDF::Writer for Ruby. This introduction covers basic creation, partial document generation and customization, and Rails-generated documents.
Technorati Tags: Austin Ziegler, PDF::Writer for Ruby