PDF::Writer for Ruby

by Satish Talim on February 26, 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: ,

Posted by Satish Talim

{ 4 comments… read them below or add one }

diva July 11, 2010 at 11:51 am

sir i am a newbie in ruby and i want to create pdf using pdf writer, unfortunatelly i had a problem like this..

hello.rb:12:in ‘require’: C:/Ruby/lib/ruby/gems/1.9.1/gems/pdf-writer-1.1.8/lib/pdf/writer.rb:712:invalid multibyte char (US-ASCII) (SyntaxError)

and like that..
then in the end there is
from hello.rb:12:in ‘(main)’

so can you tell me why and what should i do with that??


diva July 12, 2010 at 8:27 am

sorry, now the problem is the rubygems error to load pdf-writer..
then what should i do??


Jose Hernandez January 27, 2012 at 7:48 am

I have the same problem… how did you solve it?


John October 19, 2010 at 1:42 am

Hello. Can I install this application for Windows?


Leave a Comment

Previous post:

Next post: