eventioz-pdf-writer 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/ChangeLog +113 -0
- data/Demo-README +43 -0
- data/Gemfile +4 -0
- data/LICENCE +131 -0
- data/README +33 -0
- data/Rakefile +1 -0
- data/Release-Announcement +87 -0
- data/bin/techbook +24 -0
- data/bugs/first_page_margins.rb +28 -0
- data/bugs/page_numbering_simple.rb +14 -0
- data/bugs/page_numbering_stop_and_start.rb +21 -0
- data/demo/chunkybacon.rb +36 -0
- data/demo/code.rb +71 -0
- data/demo/colornames.rb +47 -0
- data/demo/demo.rb +73 -0
- data/demo/gettysburg.rb +66 -0
- data/demo/hello.rb +26 -0
- data/demo/individual-i.rb +89 -0
- data/demo/pac.rb +70 -0
- data/demo/qr-language.rb +580 -0
- data/demo/qr-library.rb +380 -0
- data/images/bluesmoke.jpg +0 -0
- data/images/chunkybacon.jpg +0 -0
- data/images/chunkybacon.png +0 -0
- data/lib/pdf/charts.rb +13 -0
- data/lib/pdf/charts/stddev.rb +431 -0
- data/lib/pdf/core_ext/mutex.rb +11 -0
- data/lib/pdf/math.rb +108 -0
- data/lib/pdf/quickref.rb +333 -0
- data/lib/pdf/simpletable.rb +948 -0
- data/lib/pdf/techbook.rb +905 -0
- data/lib/pdf/writer.rb +2734 -0
- data/lib/pdf/writer/arc4.rb +63 -0
- data/lib/pdf/writer/fontmetrics.rb +203 -0
- data/lib/pdf/writer/fonts/Courier-Bold.afm +342 -0
- data/lib/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
- data/lib/pdf/writer/fonts/Courier-Oblique.afm +342 -0
- data/lib/pdf/writer/fonts/Courier.afm +342 -0
- data/lib/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
- data/lib/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/lib/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
- data/lib/pdf/writer/fonts/Helvetica.afm +3051 -0
- data/lib/pdf/writer/fonts/MustRead.html +19 -0
- data/lib/pdf/writer/fonts/Symbol.afm +213 -0
- data/lib/pdf/writer/fonts/Times-Bold.afm +2588 -0
- data/lib/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
- data/lib/pdf/writer/fonts/Times-Italic.afm +2667 -0
- data/lib/pdf/writer/fonts/Times-Roman.afm +2419 -0
- data/lib/pdf/writer/fonts/ZapfDingbats.afm +225 -0
- data/lib/pdf/writer/graphics.rb +817 -0
- data/lib/pdf/writer/graphics/imageinfo.rb +365 -0
- data/lib/pdf/writer/lang.rb +43 -0
- data/lib/pdf/writer/lang/en.rb +99 -0
- data/lib/pdf/writer/object.rb +23 -0
- data/lib/pdf/writer/object/action.rb +35 -0
- data/lib/pdf/writer/object/annotation.rb +42 -0
- data/lib/pdf/writer/object/catalog.rb +39 -0
- data/lib/pdf/writer/object/contents.rb +70 -0
- data/lib/pdf/writer/object/destination.rb +40 -0
- data/lib/pdf/writer/object/encryption.rb +53 -0
- data/lib/pdf/writer/object/font.rb +72 -0
- data/lib/pdf/writer/object/fontdescriptor.rb +34 -0
- data/lib/pdf/writer/object/fontencoding.rb +40 -0
- data/lib/pdf/writer/object/image.rb +304 -0
- data/lib/pdf/writer/object/info.rb +51 -0
- data/lib/pdf/writer/object/outline.rb +30 -0
- data/lib/pdf/writer/object/outlines.rb +30 -0
- data/lib/pdf/writer/object/page.rb +195 -0
- data/lib/pdf/writer/object/pages.rb +115 -0
- data/lib/pdf/writer/object/procset.rb +46 -0
- data/lib/pdf/writer/object/viewerpreferences.rb +74 -0
- data/lib/pdf/writer/ohash.rb +58 -0
- data/lib/pdf/writer/oreader.rb +25 -0
- data/lib/pdf/writer/state.rb +48 -0
- data/lib/pdf/writer/strokestyle.rb +138 -0
- data/manual.pwd +5965 -0
- data/metaconfig +13 -0
- data/pdf-writer.gemspec +28 -0
- data/pre-setup.rb +56 -0
- data/setup.rb +1366 -0
- data/test/helper.rb +4 -0
- data/test/test_image_info.rb +16 -0
- data/test/test_page_numbering.rb +13 -0
- metadata +196 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# this code shows that the margin settings are being ignored for the first page.
|
2
|
+
require File.dirname(__FILE__) + "/../lib/pdf/writer"
|
3
|
+
|
4
|
+
first_name = "<b>Joseph M.</b>"
|
5
|
+
last_name = "Carmichael"
|
6
|
+
company = "WSI Sound and Web Solutions"
|
7
|
+
title = "Founder and CEO, Serial Entrepreneur extra extra"
|
8
|
+
tags = %w(research social technology burningman gobots transformers)
|
9
|
+
|
10
|
+
pdf = PDF::Writer.new(:paper => [0,0,288,432]) # A6
|
11
|
+
pdf.margins_pt(5, 5, 0, 5)
|
12
|
+
pdf.select_font "Helvetica"
|
13
|
+
|
14
|
+
(0..5).each do |page|
|
15
|
+
pdf.fill_color Color::RGB::White
|
16
|
+
pdf.text first_name, :font_size => 42, :justification => :center
|
17
|
+
pdf.text last_name, :font_size => 38, :justification => :center
|
18
|
+
pdf.move_pointer(12)
|
19
|
+
pdf.fill_color Color::RGB::LightGrey
|
20
|
+
pdf.text company, :font_size => 18, :justification => :center
|
21
|
+
pdf.text title, :font_size => 18, :justification => :center
|
22
|
+
pdf.fill_color Color::RGB::Black
|
23
|
+
pdf.move_pointer(22)
|
24
|
+
pdf.text tags.collect{|t| " #{t} <C:bullet />"}.join(' '), :font_size => 14, :justification => :center
|
25
|
+
pdf.start_new_page
|
26
|
+
end
|
27
|
+
|
28
|
+
File.open("hello.pdf", "wb") { |f| f.write pdf.render }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lib/pdf/writer"
|
2
|
+
|
3
|
+
pdf = PDF::Writer.new
|
4
|
+
pdf.text "Using Version #{PDF::Writer::VERSION}"
|
5
|
+
#Page 1 of 3 with pdf version dispayed
|
6
|
+
|
7
|
+
sa = pdf.start_page_numbering(5, 60, 9, nil, nil)
|
8
|
+
pdf.start_new_page #page 2 of 3
|
9
|
+
pdf.start_new_page #page 3 of 3
|
10
|
+
|
11
|
+
# Uncomment to fix behaviour, but this should not be needed!
|
12
|
+
# pdf.stop_page_numbering(true)
|
13
|
+
|
14
|
+
pdf.save_as "page_numbering_simple.pdf"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lib/pdf/writer"
|
2
|
+
|
3
|
+
pdf = PDF::Writer.new
|
4
|
+
pdf.text "Using Version #{PDF::Writer::VERSION}"
|
5
|
+
#Page 1 of 3 with pdf version dispayed
|
6
|
+
|
7
|
+
sa = pdf.start_page_numbering(5, 60, 9, nil, nil)
|
8
|
+
pdf.start_new_page #page 2 of 3
|
9
|
+
pdf.start_new_page #page 3 of 3
|
10
|
+
|
11
|
+
pdf.stop_page_numbering(true, :current, sa)
|
12
|
+
pdf.start_new_page #blank page
|
13
|
+
|
14
|
+
pdf.start_new_page #page 1 of 4
|
15
|
+
sc = pdf.start_page_numbering(5, 40, 9, nil, nil)
|
16
|
+
pdf.start_new_page #page 2 of 4
|
17
|
+
pdf.start_new_page #page 3 of 4
|
18
|
+
pdf.start_new_page #page 4 of 4
|
19
|
+
pdf.stop_page_numbering(true, :current, sc)
|
20
|
+
pdf.start_new_page #blank page
|
21
|
+
pdf.save_as "page_numbering_stop_and_start.pdf"
|
data/demo/chunkybacon.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# Images used in this demo are copyright 2004 - 2005 Why the Lucky Stiff
|
10
|
+
# and are from "Why's (Poignant) Guide to Ruby" at
|
11
|
+
# <http://poignantguide.net/ruby> with permission.
|
12
|
+
#
|
13
|
+
# $Id$
|
14
|
+
#++
|
15
|
+
begin
|
16
|
+
require 'pdf/writer'
|
17
|
+
rescue LoadError => le
|
18
|
+
if le.message =~ %r{pdf/writer$}
|
19
|
+
$LOAD_PATH.unshift("../lib")
|
20
|
+
require 'pdf/writer'
|
21
|
+
else
|
22
|
+
raise
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
pdf = PDF::Writer.new
|
27
|
+
pdf.select_font "Times-Roman"
|
28
|
+
pdf.text "Chunky Bacon!!", :font_size => 72, :justification => :center
|
29
|
+
|
30
|
+
i0 = pdf.image "../images/chunkybacon.jpg", :resize => 0.75
|
31
|
+
i1 = pdf.image "../images/chunkybacon.png", :justification => :center, :resize => 0.75
|
32
|
+
pdf.image i0, :justification => :right, :resize => 0.75
|
33
|
+
|
34
|
+
pdf.text "Chunky Bacon!!", :font_size => 72, :justification => :center
|
35
|
+
|
36
|
+
pdf.save_as("chunkybacon.pdf")
|
data/demo/code.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# The code in this file is highly experimental and is not generally ready
|
10
|
+
# for use. I can't figure out why the stuff *after* is so far to the right.
|
11
|
+
# I'll need to play with the X position some to get it right. This will NOT
|
12
|
+
# make it into the 1.0 release. Maybe 1.1 or 1.2.
|
13
|
+
#
|
14
|
+
# $Id$
|
15
|
+
#++
|
16
|
+
begin
|
17
|
+
require 'pdf/writer'
|
18
|
+
rescue LoadError => le
|
19
|
+
if le.message =~ %r{pdf/writer$}
|
20
|
+
$LOAD_PATH.unshift("../lib")
|
21
|
+
require 'pdf/writer'
|
22
|
+
else
|
23
|
+
raise
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
pdf = PDF::Writer.new
|
28
|
+
pdf.select_font "Times-Roman"
|
29
|
+
|
30
|
+
class TagCodeFont
|
31
|
+
FONT_NAME = "Courier"
|
32
|
+
FONT_ENCODING = nil
|
33
|
+
FONT_SIZE_DIFF = 0.9
|
34
|
+
|
35
|
+
class << self
|
36
|
+
attr_accessor :font_name
|
37
|
+
|
38
|
+
def [](pdf, info)
|
39
|
+
@font_name ||= FONT_NAME
|
40
|
+
@font_encoding ||= FONT_ENCODING
|
41
|
+
|
42
|
+
case info[:status]
|
43
|
+
when :start, :start_line
|
44
|
+
@__fontinfo ||= {}
|
45
|
+
@__fontinfo[info[:cbid]] = {
|
46
|
+
:font => pdf.current_font,
|
47
|
+
:base_font => pdf.current_base_font,
|
48
|
+
:info => info
|
49
|
+
}
|
50
|
+
|
51
|
+
pdf.select_font(@font_name, @font_encoding)
|
52
|
+
|
53
|
+
{ :font_change => true }
|
54
|
+
when :end, :end_line
|
55
|
+
fi = @__fontinfo[info[:cbid]]
|
56
|
+
|
57
|
+
pdf.font_size = fi[:font_size]
|
58
|
+
pdf.select_font(fi[:base_font])
|
59
|
+
pdf.select_font(fi[:font])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
PDF::Writer::TAGS[:pair]["code"] = TagCodeFont
|
66
|
+
|
67
|
+
pdf.text "Hello, <c:code>Ruby</c:code>.", :font_size => 72, :justification => :center
|
68
|
+
pdf.move_pointer(80)
|
69
|
+
pdf.text "This is a longer <c:code>sample of code font text</c:code>. What do you think?", :font_size => 12, :justification => :full
|
70
|
+
|
71
|
+
pdf.save_as("code.pdf")
|
data/demo/colornames.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id$
|
10
|
+
#++
|
11
|
+
begin
|
12
|
+
require 'pdf/writer'
|
13
|
+
rescue LoadError => le
|
14
|
+
if le.message =~ %r{pdf/writer$}
|
15
|
+
$LOAD_PATH.unshift("../lib")
|
16
|
+
require 'pdf/writer'
|
17
|
+
else
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'color/rgb/metallic'
|
23
|
+
|
24
|
+
pdf = PDF::Writer.new
|
25
|
+
|
26
|
+
pdf.start_columns 4
|
27
|
+
|
28
|
+
colours = Color::RGB.constants.sort
|
29
|
+
|
30
|
+
colours.each do |colour|
|
31
|
+
next if colour == "PDF_FORMAT_STR"
|
32
|
+
next if colour == "Metallic"
|
33
|
+
pdf.fill_color Color::RGB.const_get(colour)
|
34
|
+
pdf.text colour, :font_size => 24
|
35
|
+
pdf.fill_color Color::RGB::Black
|
36
|
+
pdf.text colour, :font_size => 12, :justification => :center
|
37
|
+
end
|
38
|
+
|
39
|
+
colours = Color::RGB::Metallic.constants.sort
|
40
|
+
colours.each do |colour|
|
41
|
+
pdf.fill_color Color::RGB::Metallic.const_get(colour)
|
42
|
+
pdf.text colour, :font_size => 24
|
43
|
+
pdf.fill_color Color::RGB::Black
|
44
|
+
pdf.text colour, :font_size => 12, :justification => :center
|
45
|
+
end
|
46
|
+
|
47
|
+
pdf.save_as "colornames.pdf"
|
data/demo/demo.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id$
|
10
|
+
#++
|
11
|
+
begin
|
12
|
+
require 'pdf/writer'
|
13
|
+
rescue LoadError => le
|
14
|
+
if le.message =~ %r{pdf/writer$}
|
15
|
+
$LOAD_PATH.unshift("../lib")
|
16
|
+
require 'pdf/writer'
|
17
|
+
else
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if ARGV.empty?
|
23
|
+
line = 'Ruby Rocks'
|
24
|
+
else
|
25
|
+
line = ARGV.join(" ")
|
26
|
+
end
|
27
|
+
|
28
|
+
pdf = PDF::Writer.new
|
29
|
+
|
30
|
+
# Do some funky stuff in the background, in a nice light blue, which is
|
31
|
+
# bound to clash with something and some red for the hell of it
|
32
|
+
x = 578
|
33
|
+
r1 = 25
|
34
|
+
|
35
|
+
40.step(1, -3) do |xw|
|
36
|
+
tone = 1.0 - (xw / 40.0) * 0.2
|
37
|
+
|
38
|
+
pdf.stroke_style(PDF::Writer::StrokeStyle.new(xw))
|
39
|
+
pdf.stroke_color(Color::RGB.from_fraction(tone, 1, tone))
|
40
|
+
pdf.circle_at(50, 750, r1).stroke
|
41
|
+
r1 += xw
|
42
|
+
end
|
43
|
+
|
44
|
+
40.step(1, -3) do |xw|
|
45
|
+
tone = 1.0 - (xw / 40.0) * 0.2
|
46
|
+
|
47
|
+
pdf.stroke_style(PDF::Writer::StrokeStyle.new(xw))
|
48
|
+
pdf.stroke_color(Color::RGB.from_fraction(tone, tone, 1))
|
49
|
+
pdf.line(x, 0, x, 842)
|
50
|
+
x = (x - xw - 2)
|
51
|
+
end
|
52
|
+
|
53
|
+
pdf.stroke_color(Color::RGB::Black)
|
54
|
+
pdf.stroke_style(PDF::Writer::StrokeStyle.new(1))
|
55
|
+
pdf.rectangle(20, 20, 558, 802)
|
56
|
+
|
57
|
+
y = 800
|
58
|
+
50.step(5, -5) do |size|
|
59
|
+
height = pdf.font_height(size)
|
60
|
+
y = y - height
|
61
|
+
|
62
|
+
pdf.add_text(30, y, line, size)
|
63
|
+
end
|
64
|
+
|
65
|
+
(0...360).step(20) do |angle|
|
66
|
+
pdf.fill_color(Color::RGB.from_fraction(rand, rand, rand))
|
67
|
+
|
68
|
+
pdf.add_text(300 + Math.cos(PDF::Math.deg2rad(angle)) * 40,
|
69
|
+
300 + Math.sin(PDF::Math.deg2rad(angle)) * 40,
|
70
|
+
line, 20, angle)
|
71
|
+
end
|
72
|
+
|
73
|
+
pdf.save_as("demo.pdf")
|
data/demo/gettysburg.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id$
|
10
|
+
#++
|
11
|
+
begin
|
12
|
+
require 'pdf/writer'
|
13
|
+
rescue LoadError => le
|
14
|
+
if le.message =~ %r{pdf/writer$}
|
15
|
+
$LOAD_PATH.unshift("../lib")
|
16
|
+
require 'pdf/writer'
|
17
|
+
else
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
pdf = PDF::Writer.new
|
23
|
+
|
24
|
+
GETTYSBURG = <<-'EOS'
|
25
|
+
Four score and seven years ago our fathers brought forth on this
|
26
|
+
continent a new nation, conceived in liberty and dedicated to the
|
27
|
+
proposition that all men are created equal. Now we are engaged in
|
28
|
+
a great civil war, testing whether that nation or any nation so
|
29
|
+
conceived and so dedicated can long endure. We are met on a great
|
30
|
+
battlefield of that war. We have come to dedicate a portion of
|
31
|
+
that field as a final resting-place for those who here gave their
|
32
|
+
lives that that nation might live. It is altogether fitting and
|
33
|
+
proper that we should do this. But in a larger sense, we cannot
|
34
|
+
dedicate, we cannot consecrate, we cannot hallow this ground.
|
35
|
+
The brave men, living and dead who struggled here have consecrated
|
36
|
+
it far above our poor power to add or detract. The world will
|
37
|
+
little note nor long remember what we say here, but it can never
|
38
|
+
forget what they did here. It is for us the living rather to be
|
39
|
+
dedicated here to the unfinished work which they who fought here
|
40
|
+
have thus far so nobly advanced. It is rather for us to be here
|
41
|
+
dedicated to the great task remaining before us�that from these
|
42
|
+
honored dead we take increased devotion to that cause for which
|
43
|
+
they gave the last full measure of devotion�that we here highly
|
44
|
+
resolve that these dead shall not have died in vain, that this
|
45
|
+
nation under God shall have a new birth of freedom, and that
|
46
|
+
government of the people, by the people, for the people shall
|
47
|
+
not perish from the earth.
|
48
|
+
EOS
|
49
|
+
|
50
|
+
gba = GETTYSBURG.split($/).join(" ").squeeze(" ")
|
51
|
+
|
52
|
+
pdf.text "The Gettysburg Address\n\n", :font_size => 36,
|
53
|
+
:justification => :center
|
54
|
+
|
55
|
+
y0 = pdf.y + 18
|
56
|
+
pdf.text gba, :justification => :full, :font_size => 14, :left => 50,
|
57
|
+
:right => 50
|
58
|
+
pdf.move_pointer(36)
|
59
|
+
pdf.text "U.S. President Abraham Lincoln, 19 November 1863",
|
60
|
+
:justification => :right, :right => 100
|
61
|
+
pdf.text "Gettysburg, Pennsylvania", :justification => :right, :right => 100
|
62
|
+
|
63
|
+
pdf.rounded_rectangle(pdf.left_margin + 25, y0, pdf.margin_width - 50,
|
64
|
+
y0 - pdf.y + 18, 10).stroke
|
65
|
+
|
66
|
+
pdf.save_as("gettysburg.pdf")
|
data/demo/hello.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id$
|
10
|
+
#++
|
11
|
+
begin
|
12
|
+
require 'pdf/writer'
|
13
|
+
rescue LoadError => le
|
14
|
+
if le.message =~ %r{pdf/writer$}
|
15
|
+
$LOAD_PATH.unshift("../lib")
|
16
|
+
require 'pdf/writer'
|
17
|
+
else
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
pdf = PDF::Writer.new
|
23
|
+
pdf.select_font "Times-Roman"
|
24
|
+
pdf.text "Hello, Ruby.", :font_size => 72, :justification => :center
|
25
|
+
|
26
|
+
pdf.save_as("hello.pdf")
|
@@ -0,0 +1,89 @@
|
|
1
|
+
#--
|
2
|
+
# PDF::Writer for Ruby.
|
3
|
+
# http://rubyforge.org/projects/ruby-pdf/
|
4
|
+
# Copyright 2003 - 2005 Austin Ziegler.
|
5
|
+
#
|
6
|
+
# Licensed under a MIT-style licence. See LICENCE in the main distribution
|
7
|
+
# for full licensing information.
|
8
|
+
#
|
9
|
+
# $Id$
|
10
|
+
#++
|
11
|
+
begin
|
12
|
+
require 'pdf/writer'
|
13
|
+
rescue LoadError => le
|
14
|
+
if le.message =~ %r{pdf/writer$}
|
15
|
+
$LOAD_PATH.unshift("../lib")
|
16
|
+
require 'pdf/writer'
|
17
|
+
else
|
18
|
+
raise
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'color/palette/monocontrast'
|
23
|
+
|
24
|
+
class IndividualI
|
25
|
+
def initialize(size = 100)
|
26
|
+
@size = size
|
27
|
+
end
|
28
|
+
|
29
|
+
# The size of the "i" in points.
|
30
|
+
attr_accessor :size
|
31
|
+
|
32
|
+
def half_i(pdf)
|
33
|
+
pdf.move_to(0, 82)
|
34
|
+
pdf.line_to(0, 78)
|
35
|
+
pdf.line_to(9, 78)
|
36
|
+
pdf.line_to(9, 28)
|
37
|
+
pdf.line_to(0, 28)
|
38
|
+
pdf.line_to(0, 23)
|
39
|
+
pdf.line_to(18, 23)
|
40
|
+
pdf.line_to(18, 82)
|
41
|
+
pdf.fill
|
42
|
+
end
|
43
|
+
private :half_i
|
44
|
+
|
45
|
+
def draw(pdf, x, y)
|
46
|
+
pdf.save_state
|
47
|
+
pdf.translate_axis(x, y)
|
48
|
+
pdf.scale_axis(1 * (@size / 100.0), -1 * (@size / 100.0))
|
49
|
+
|
50
|
+
pdf.circle_at(20, 10, 7.5)
|
51
|
+
pdf.fill
|
52
|
+
|
53
|
+
half_i(pdf)
|
54
|
+
|
55
|
+
pdf.translate_axis(40, 0)
|
56
|
+
pdf.scale_axis(-1, 1)
|
57
|
+
|
58
|
+
half_i(pdf)
|
59
|
+
|
60
|
+
pdf.restore_state
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
pdf = PDF::Writer.new
|
65
|
+
ii = IndividualI.new(24)
|
66
|
+
|
67
|
+
x = pdf.absolute_left_margin
|
68
|
+
y = pdf.absolute_top_margin
|
69
|
+
|
70
|
+
bg = Color::RGB.from_fraction(rand, rand, rand)
|
71
|
+
fg = Color::RGB.from_fraction(rand, rand, rand)
|
72
|
+
pal = Color::Palette::MonoContrast.new(bg, fg)
|
73
|
+
|
74
|
+
sz = 24
|
75
|
+
|
76
|
+
(-5..5).each do |col|
|
77
|
+
pdf.fill_color pal.background[col]
|
78
|
+
ii.draw(pdf, x, y)
|
79
|
+
ii.size += sz
|
80
|
+
x += sz / 2.0
|
81
|
+
y -= sz / 2.0
|
82
|
+
pdf.fill_color pal.foreground[col]
|
83
|
+
ii.draw(pdf, x, y)
|
84
|
+
x += sz / 2.0
|
85
|
+
y -= sz / 2.0
|
86
|
+
ii.size += sz
|
87
|
+
end
|
88
|
+
|
89
|
+
pdf.save_as("individual-i.pdf")
|