Professional Documents
Culture Documents
Library
Before getting started with this tutorial, I would like to thanks Greg and Prawn
team for their awesome work towards ruby and rails community.
or
config.gem ‘prawn’
Optionally you can specify version to be used and then run task
rake gems:install
./script/console
pdf = Prawn::Document.new
It creates new pdf document object. Here you can additionally pass options
parameters such as -
Prawn::Document.new(:page_size => [11.32, 8.49], :page_layout => :portrait)
pdf.text("Prawn Rocks")
=> 12
pdf.render_file('prawn.pdf')
pdf = Prawn::Document.new('A3') do
1. FONTS [click]
font "times.ttf"
font("/times.ttf")
2. TEXT [click]
text “Sandip Ransing”, :size => 41, :position => :center, :style => :bold
stroke do
end
4. IMAGE [click]
image 'sandip.png', :height => 50, :position => :center, :border => 2
Scale Image
require "open-uri"
image
open(“http://t2.gstatic.com/images?q=tbn:kTG6gAKrnou2gM:http://www.faceb
ook.com/profile/pic.php?uid=AAAAAQAQrLXvTWfyY2ANjttV8D1c0QAAA
AnDHPFJe0pPFR84iIzXPKro&t=1")
end
5. LINE BREAKS
movedown(20)
6. TABLE/GRID [click]
data = [
["Name", {:text => 'Sandip Ransing', :font_style => :bold, :colspan => 4 }],
[{:text => "Areas of Speciality", :font_style => :bold}, {:text => "Ruby,
Rails, Radiant, Asterisk, Adhearsion, Geokit, Prawn, ....,...", :font_style =>
:bold, :colspan => 4}],
[{:text => "Company", :colspan => 2},{:text => "Josh Software", :colspan
=> 3}]
table data,
:horizontal_padding => 6,
:vertical_padding => 3,
:column_widths => { 0 => 130, 1 => 100, 2 => 100, 3 => 100, 4 => 80 },
:align => { 0 => :left, 1 => :right, 2 => :left, 3 => :right, 4 => :right }
7. LINKS [click]
8. PDF Security
Prawn-format supports inline text formatting that gives user enough flexibility
to use html tags.
require ‘prawn/format’
end
pdf.render_file “my.pdf”
!!! NOTE: As of time now prawn-format is incompatible with latest prawn gem, It is compatible
with prawn version <= 0.6 s