Path: | README |
Last Update: | Mon Nov 29 01:58:59 +0000 2010 |
Prawn is a PDF writing library for Ruby designed to be tiny, fast, and nimble, just like the majestic sea creature.
Development on this library was initially made possible thanks to the many people who donated to the Ruby Mendicant project: rubymendicant.wikidot.com
The project is currently maintained by Gregory Brown, with lots of help from the community.
Getting started with Prawn can be as simple as:
require 'prawn' pdf = Prawn::Document.new pdf.text("Prawn Rocks") pdf.render_file('prawn.pdf')
But prawn can do a lot more:
Prawn::Document.new('A0')
…gives you an really big page.
Prawn::Document.new(:page_size => [11.32, 8.49], :page_layout => :portrait)
…giving you a postage stamp.
pdf.text("Prawn Rocks") pdf.font("/myfont.ttf") pdf.text("Prawn still rocks in a different font")
…allowing you to use any font you want.
Simple shapes:
pdf.stroke do pdf.circle_at [100,100], :radius => 25 pdf.rectangle [300,300], 100, 200 end
(note, you need to stroke the path to put "ink" there)
Reading an image directly from a file:
prawn_logo = "#{Prawn::BASEDIR}/data/images/prawn_logo.png" pdf.image prawn_logo, :at => [50,450], :width => 450
Or reading it from an IO stream:
require "open-uri" pdf.image open("http://prawn.majesticseacreature.com/media/prawn_logo.png")
Prawn deals exclusively in PDF points… which work out to about 2.83464567mm… don‘t try and do it in your head, instead, let Prawn help you:
require "prawn/measurement_extensions" Prawn::Document.generate(:page_layout => :portrait, :left_margin => 10.mm, # different :right_margin => 1.cm, # units :top_margin => 0.1.dm, # work :bottom_margin => 0.01.m, # well :page_size => 'A4') do text "Prawn Rocks" end
github.com/sandal/prawn/tree/stable/examples
For tables and grid based layout:
github.com/sandal/prawn-layout/tree/stable/examples
For inline styling and advanced formatting:
github.com/sandal/prawn-format/tree/stable/examples
For encryption, password protection, and permissions:
github.com/madriska/prawn-security/tree/stable/examples
(or gem unpack prawn-core, prawn-format, prawn-security and prawn-layout if you want to run them locally)
github.com/sandal/prawn/issues github.com/sandal/prawn-layout/issues github.com/sandal/prawn-format/issues github.com/madriska/prawn-security/issues
github.com/sandal/prawn github.com/sandal/prawn-layout github.com/sandal/prawn-format github.com/madriska/prawn-security
groups.google.com/group/prawn-ruby
Find us in prawn on irc.freenode.net
Gregory Brown: <sandal> James Healy: <yob>
See HACKING file for details on getting set up with a local build.