rghost-ruby1.9-beta 0.8.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rghost.rb +18 -0
- data/lib/rghost/border.rb +44 -0
- data/lib/rghost/callback.rb +58 -0
- data/lib/rghost/circle.rb +102 -0
- data/lib/rghost/color.rb +175 -0
- data/lib/rghost/constants.rb +626 -0
- data/lib/rghost/convert.rb +43 -0
- data/lib/rghost/cursor.rb +124 -0
- data/lib/rghost/dash.rb +59 -0
- data/lib/rghost/document.rb +546 -0
- data/lib/rghost/document_callback_facade.rb +64 -0
- data/lib/rghost/dsc_entry.rb +20 -0
- data/lib/rghost/dynamic_document_callback.rb +15 -0
- data/lib/rghost/eps.rb +31 -0
- data/lib/rghost/font.rb +48 -0
- data/lib/rghost/font_map.rb +54 -0
- data/lib/rghost/frame.rb +105 -0
- data/lib/rghost/function.rb +38 -0
- data/lib/rghost/gif.rb +41 -0
- data/lib/rghost/graphic.rb +26 -0
- data/lib/rghost/grid/base_grid.rb +228 -0
- data/lib/rghost/grid/callback_facade.rb +136 -0
- data/lib/rghost/grid/csv_grid.rb +51 -0
- data/lib/rghost/grid/dynamic_callback.rb +12 -0
- data/lib/rghost/grid/field_format.rb +43 -0
- data/lib/rghost/grid/grid.rb +15 -0
- data/lib/rghost/grid/header.rb +120 -0
- data/lib/rghost/grid/matrix.rb +10 -0
- data/lib/rghost/grid/rails_grid.rb +74 -0
- data/lib/rghost/grid/static_callback.rb +13 -0
- data/lib/rghost/grid/style/border_lines.rb +44 -0
- data/lib/rghost/grid/style/bottom_lines.rb +28 -0
- data/lib/rghost/grid/style/old_forms.rb +28 -0
- data/lib/rghost/grid/style/style.rb +8 -0
- data/lib/rghost/gs_alone.rb +25 -0
- data/lib/rghost/helpers.rb +13 -0
- data/lib/rghost/horizontal_line.rb +45 -0
- data/lib/rghost/how_to.rb +75 -0
- data/lib/rghost/image.rb +26 -0
- data/lib/rghost/jpeg.rb +39 -0
- data/lib/rghost/line.rb +89 -0
- data/lib/rghost/line_width.rb +28 -0
- data/lib/rghost/load.rb +43 -0
- data/lib/rghost/newpath.rb +19 -0
- data/lib/rghost/paper.rb +147 -0
- data/lib/rghost/parse_text.rb +53 -0
- data/lib/rghost/pdf_security.rb +36 -0
- data/lib/rghost/point.rb +23 -0
- data/lib/rghost/point_with_command.rb +17 -0
- data/lib/rghost/polygon.rb +75 -0
- data/lib/rghost/ps/AdobeExpert.enc +258 -0
- data/lib/rghost/ps/AdobeLatinEncoding.enc +258 -0
- data/lib/rghost/ps/Bengali.enc +386 -0
- data/lib/rghost/ps/CodePage1250.enc +258 -0
- data/lib/rghost/ps/CodePage1251.enc +258 -0
- data/lib/rghost/ps/CodePage1252.enc +258 -0
- data/lib/rghost/ps/CodePage1253.enc +258 -0
- data/lib/rghost/ps/CodePage1254.enc +258 -0
- data/lib/rghost/ps/CodePage1256.enc +258 -0
- data/lib/rghost/ps/CodePage1257.enc +258 -0
- data/lib/rghost/ps/CodePage1258.enc +258 -0
- data/lib/rghost/ps/CodePage874.enc +258 -0
- data/lib/rghost/ps/Fontmap +5 -0
- data/lib/rghost/ps/IsoLatin.enc +352 -0
- data/lib/rghost/ps/MacCentralEuropean.enc +258 -0
- data/lib/rghost/ps/MacCyrillice.desnc +258 -0
- data/lib/rghost/ps/MacGreek.enc +258 -0
- data/lib/rghost/ps/MacHebrew.enc +258 -0
- data/lib/rghost/ps/TeX-CorkEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-LGR-Greek.enc +258 -0
- data/lib/rghost/ps/TeX-T2AModified2Encoding.enc +258 -0
- data/lib/rghost/ps/TeX-T2BAdobeEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-T2CAdobeEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-X2AdobeEncoding.enc +258 -0
- data/lib/rghost/ps/TeX-XL2encoding.enc +258 -0
- data/lib/rghost/ps/TeXMathExtensionEncoding.enc +258 -0
- data/lib/rghost/ps/TeXMathItalicEncoding.enc +258 -0
- data/lib/rghost/ps/TeXMathSymbolEncoding.enc +258 -0
- data/lib/rghost/ps/US-ASCII.enc +258 -0
- data/lib/rghost/ps/UTF-8.enc +3 -0
- data/lib/rghost/ps/_cusor.ps +46 -0
- data/lib/rghost/ps/basic.ps +25 -0
- data/lib/rghost/ps/begin_document.ps +8 -0
- data/lib/rghost/ps/callbacks.ps +175 -0
- data/lib/rghost/ps/code128.font +344 -0
- data/lib/rghost/ps/code39.font +195 -0
- data/lib/rghost/ps/cursor.ps +106 -0
- data/lib/rghost/ps/datagrid.ps +55 -0
- data/lib/rghost/ps/developer.ps +237 -0
- data/lib/rghost/ps/ean.font +150 -0
- data/lib/rghost/ps/eps.ps +42 -0
- data/lib/rghost/ps/font.ps +38 -0
- data/lib/rghost/ps/frame.ps +16 -0
- data/lib/rghost/ps/gif.ps +150 -0
- data/lib/rghost/ps/horizontal_line.ps +4 -0
- data/lib/rghost/ps/i25.font +103 -0
- data/lib/rghost/ps/jpeg.ps +122 -0
- data/lib/rghost/ps/link.ps +22 -0
- data/lib/rghost/ps/paper.ps +8 -0
- data/lib/rghost/ps/rect_link.ps +17 -0
- data/lib/rghost/ps/rectangle.ps +5 -0
- data/lib/rghost/ps/rghost_default_template.eps +1532 -0
- data/lib/rghost/ps/row.ps +4 -0
- data/lib/rghost/ps/show.ps +21 -0
- data/lib/rghost/ps/table_callbacks.ps +96 -0
- data/lib/rghost/ps/text.ps +63 -0
- data/lib/rghost/ps/textarea.ps +11 -0
- data/lib/rghost/ps/type.ps +1 -0
- data/lib/rghost/ps/unit.ps +3 -0
- data/lib/rghost/ps/vertical_line.ps +12 -0
- data/lib/rghost/ps/virtual_pages.ps +55 -0
- data/lib/rghost/ps_facade.rb +253 -0
- data/lib/rghost/ps_object.rb +55 -0
- data/lib/rghost/rectangle_link.rb +65 -0
- data/lib/rghost/rgengine.so +0 -0
- data/lib/rghost/ruby_ghost_config.rb +243 -0
- data/lib/rghost/ruby_ghost_engine.rb +156 -0
- data/lib/rghost/ruby_ghost_version.rb +8 -0
- data/lib/rghost/ruby_to_ps.rb +78 -0
- data/lib/rghost/scale.rb +29 -0
- data/lib/rghost/shape_content.rb +23 -0
- data/lib/rghost/show.rb +88 -0
- data/lib/rghost/static_document_callback.rb +18 -0
- data/lib/rghost/text.rb +44 -0
- data/lib/rghost/text_in.rb +51 -0
- data/lib/rghost/text_link_in.rb +42 -0
- data/lib/rghost/textarea.rb +88 -0
- data/lib/rghost/units.rb +82 -0
- data/lib/rghost/variable.rb +12 -0
- data/lib/rghost/vertical_line.rb +37 -0
- data/lib/rghost/virtual_pages.rb +42 -0
- metadata +185 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Convert PDF file to another format using commom render parameters of the Engine
|
|
2
|
+
# A additional parameter for this method is :range. Below someone examples:
|
|
3
|
+
#
|
|
4
|
+
# ====Only cover page
|
|
5
|
+
# Convert.new("/dir/myfile.pdf").to :jpeg, :filename => "/tmp/test.jpg"
|
|
6
|
+
#
|
|
7
|
+
# ====One page per file
|
|
8
|
+
# It's generate file with pattern test_0001.png, test_0002.png, etc
|
|
9
|
+
# Convert.new("/dir/myfile.pdf").to :png, :multipage => true, :filename => "/tmp/test.png"
|
|
10
|
+
#
|
|
11
|
+
# ====One page per file with page range
|
|
12
|
+
# Convert.new("/dir/myfile.pdf").to :eps, :multipage => true, :filename => "/tmp/test.eps", :range => 1..5
|
|
13
|
+
#
|
|
14
|
+
# ====Getting files after convertion
|
|
15
|
+
# files=Convert.new("/dir/myfile.pdf").to :eps, :multipage => true, :filename => "/tmp/test.eps", :range => 1..5
|
|
16
|
+
# files.class # => Array because parameter multipage is true
|
|
17
|
+
#
|
|
18
|
+
# file=Convert.new("/dir/myfile.pdf").to :eps, :filename => "/tmp/test.eps"
|
|
19
|
+
# file.class # => File
|
|
20
|
+
#
|
|
21
|
+
class RGhost::Convert
|
|
22
|
+
attr_reader :error, :errors
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def initialize(filename)
|
|
26
|
+
@filename=filename
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def to(device, options={})
|
|
33
|
+
rge=RGhost::Engine.new(@filename,{:convert=>true}.merge(options))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
out=rge.render(device)
|
|
37
|
+
@error=rge.error
|
|
38
|
+
@errors=rge.errors
|
|
39
|
+
out
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
require "rghost/point"
|
|
2
|
+
require 'rghost/ps_object'
|
|
3
|
+
require 'rghost/point_with_command'
|
|
4
|
+
#It resposible to cursor manipulate. Use it to position objects on the page.
|
|
5
|
+
class RGhost::Cursor < RGhost::PsObject
|
|
6
|
+
|
|
7
|
+
#The class method goto positioned the cursor based on page row number. Example:
|
|
8
|
+
# d=Document.new
|
|
9
|
+
# d.goto_row 15
|
|
10
|
+
# d.show " You're on row 15"
|
|
11
|
+
# d.goto_row 3
|
|
12
|
+
# d.show "Now you're on row 3"
|
|
13
|
+
#
|
|
14
|
+
# #or without facade(**it's valid for all methods on this class**)
|
|
15
|
+
#
|
|
16
|
+
# d=Document.new
|
|
17
|
+
# d.set Cursor.goto_row(15)
|
|
18
|
+
# d.set Show.new(" You're on row 15")
|
|
19
|
+
# d.set Cursor.goto_row(3)
|
|
20
|
+
# d.set Show.new("Now you're on row 3")
|
|
21
|
+
def self.goto_row(row)
|
|
22
|
+
g=RGhost::PsObject.new(row.to_i)
|
|
23
|
+
g.call :goto_row
|
|
24
|
+
g.call :default_point
|
|
25
|
+
g
|
|
26
|
+
end
|
|
27
|
+
#Jump n rows relative to the current row
|
|
28
|
+
# d=Document.new
|
|
29
|
+
# d.jump_row 4 # jump four rows below
|
|
30
|
+
# d.jump_row -5 # backing five rows to up
|
|
31
|
+
def self.jump_rows(row)
|
|
32
|
+
j=RGhost::PsObject.new(row.to_i)
|
|
33
|
+
j.call :jump_rows
|
|
34
|
+
j.call :default_point
|
|
35
|
+
j
|
|
36
|
+
end
|
|
37
|
+
#Rotate all objects after execution it, passing the angle as argument.
|
|
38
|
+
# d=Document.new
|
|
39
|
+
# d.rotate 90
|
|
40
|
+
# #do something
|
|
41
|
+
# d.rotate -90 # backing to source angle
|
|
42
|
+
def self.rotate(angle)
|
|
43
|
+
r=RGhost::PsObject.new(angle.to_i)
|
|
44
|
+
r.call :rotate
|
|
45
|
+
r
|
|
46
|
+
end
|
|
47
|
+
#Move cursor to absolute point relative from default source point x=0 and y=0 of the page. It no interferes to the rows positions.
|
|
48
|
+
# doc=Document.new
|
|
49
|
+
# doc.moveto :x=> 10, :y=> 5
|
|
50
|
+
# doc.show "Hello Girls!!!"
|
|
51
|
+
def self.moveto(point={})
|
|
52
|
+
RGhost::PointWithCommand.to(:moveto,point)
|
|
53
|
+
end
|
|
54
|
+
#It works the same way that moveto, the unique difference it's relative from current point.
|
|
55
|
+
# doc=Document.new
|
|
56
|
+
# doc.moveto :x=> 10, :y=> 5
|
|
57
|
+
# doc.show "Hello Girls!!!"
|
|
58
|
+
# doc.rmoveto :x => 5 # move to x=> 15 (10 plus 5) maintaining y => 5
|
|
59
|
+
def self.rmoveto(point={})
|
|
60
|
+
RGhost::PointWithCommand.to(:rmoveto,point)
|
|
61
|
+
end
|
|
62
|
+
#It changes the default pont to a new point(dislocate)
|
|
63
|
+
# doc=Document.new
|
|
64
|
+
# doc.translate :x=> 2, :y=> 1
|
|
65
|
+
# doc.moveto :x => 0,:y => 0 # if it was default point(0,0) would be :x=> 2, :y=> 1
|
|
66
|
+
# doc.translate :x=> -2, :y=> -1 # return to default source point
|
|
67
|
+
def self.translate(point={:x =>0 , :y => 0})
|
|
68
|
+
p={:x =>0 , :y => 0}.merge(point)
|
|
69
|
+
RGhost::PointWithCommand.to(:translate,p)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
#Jump one next row. It's same that jump_row(1).
|
|
73
|
+
# doc=Document.new
|
|
74
|
+
# doc.show "Row 1"
|
|
75
|
+
# doc.next_row
|
|
76
|
+
# doc.show "Row 2"
|
|
77
|
+
# doc.next_row
|
|
78
|
+
# doc.show "Row 3"
|
|
79
|
+
def self.next_row
|
|
80
|
+
RGhost::PsObject.new(:nrdp)
|
|
81
|
+
end
|
|
82
|
+
#It go to next page resetting the cursors.
|
|
83
|
+
# doc=Document.new
|
|
84
|
+
# doc.show "Page 1 row 1"
|
|
85
|
+
# doc.next_page
|
|
86
|
+
# doc.show "Page 2 row 1"
|
|
87
|
+
# doc.next_page
|
|
88
|
+
# doc.show "Page 3 row 1"
|
|
89
|
+
def next_page
|
|
90
|
+
RGhost::PsObject.new :next_page
|
|
91
|
+
end
|
|
92
|
+
#It go to next page without resetting the cursors. Often used for single page document.
|
|
93
|
+
# doc=Document.new
|
|
94
|
+
# doc.show "Page 1 row 1"
|
|
95
|
+
# doc.showpage # page 2, but internally
|
|
96
|
+
# doc.show "Page 1 row 1"
|
|
97
|
+
# doc.showpage # page 3
|
|
98
|
+
# doc.show "Page 1 row 1"
|
|
99
|
+
def showpage
|
|
100
|
+
RGhost::PsObject.new :showpage
|
|
101
|
+
end
|
|
102
|
+
#(Class method) It go to next page resetting the cursors.
|
|
103
|
+
# doc=Document.new
|
|
104
|
+
# doc.show "Page 1 row 1"
|
|
105
|
+
# doc.next_page
|
|
106
|
+
# doc.show "Page 2 row 1"
|
|
107
|
+
# doc.next_page
|
|
108
|
+
# doc.show "Page 3 row 1"
|
|
109
|
+
def self.next_page
|
|
110
|
+
RGhost::PsObject.new :next_page
|
|
111
|
+
end
|
|
112
|
+
#(Class method) It go to next page without resetting the cursors. Often used for single page document.
|
|
113
|
+
# doc=Document.new
|
|
114
|
+
# doc.show "Page 1 row 1"
|
|
115
|
+
# doc.showpage # page 2, but internally
|
|
116
|
+
# doc.show "Page 1 row 1"
|
|
117
|
+
# doc.showpage # page 3
|
|
118
|
+
# doc.show "Page 1 row 1"
|
|
119
|
+
def self.showpage
|
|
120
|
+
RGhost::PsObject.new :showpage
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
data/lib/rghost/dash.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#Sets the dash pattern on border lines. It accepts an array of
|
|
2
|
+
#non-negative numbers with atleast one non-zero. Samples:
|
|
3
|
+
# [2,1] #=> 2 turn on and 1 off, 2 turn on and 1 off ...
|
|
4
|
+
# [3,1,2,5] #=> 3 on, 1 off, 2 on, 5 off ... repeating until end
|
|
5
|
+
#
|
|
6
|
+
#
|
|
7
|
+
#===Examples using dash as border parameter
|
|
8
|
+
# d=Document.new
|
|
9
|
+
# d.horizontal_line(:bottom, :border=>{:dash => 1, :width => 2 })
|
|
10
|
+
#link:images/dash01.png
|
|
11
|
+
#
|
|
12
|
+
# d=Document.new
|
|
13
|
+
# d.horizontal_line(:bottom, :border=>{:dash => [1,1], :width => 2 })
|
|
14
|
+
#link:images/dash01.png
|
|
15
|
+
#
|
|
16
|
+
# d=Document.new
|
|
17
|
+
# d.horizontal_line(:bottom, :border=>{:dash => [1,2,1], :width => 2 })
|
|
18
|
+
#link:images/dash03.png
|
|
19
|
+
#
|
|
20
|
+
# d=Document.new
|
|
21
|
+
# d.horizontal_line(:bottom, :border=>{:dash => [2,10,5], :width => 2 })
|
|
22
|
+
#link:images/dash04.png
|
|
23
|
+
#
|
|
24
|
+
# d=Document.new
|
|
25
|
+
# d.horizontal_line(:bottom, :border=>{:dash => [1,1,3,1,5,1,7,1,9,1,10], :width => 4 })
|
|
26
|
+
#link:images/dash05.png
|
|
27
|
+
#
|
|
28
|
+
#===Examples using Dash class
|
|
29
|
+
# d=Document.new
|
|
30
|
+
# d.scale(1,8)
|
|
31
|
+
# d.set Dash.new([1,1,2,1,2,1,3])
|
|
32
|
+
# d.line_width 3
|
|
33
|
+
# d.lineto :x => :limit_right, :y => :Y
|
|
34
|
+
#link:images/dash06.png
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class RGhost::Dash < RGhost::PsObject
|
|
38
|
+
include RGhost::RubyToPs
|
|
39
|
+
DEFAULT_OPTIONS={
|
|
40
|
+
:style => [1,2,3],
|
|
41
|
+
:offset => 0
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def initialize(options={})
|
|
46
|
+
super(""){}
|
|
47
|
+
if options.is_a?(Numeric) || options.is_a?(Array)
|
|
48
|
+
@options = DEFAULT_OPTIONS.dup.merge(:style => options)
|
|
49
|
+
else
|
|
50
|
+
@options = DEFAULT_OPTIONS.dup.merge(options)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def ps
|
|
55
|
+
ary=to_array( [@options[:style]].flatten)
|
|
56
|
+
"#{ary}#{@options[:offset]} setdash"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
##
|
|
2
|
+
#Ruby Ghost Engine - Document Builder.
|
|
3
|
+
#http://rghost.rubyforge.org
|
|
4
|
+
#Author Shairon Toledo <shairon.toledo at gmail.com> http://www.hashcode.eti.br
|
|
5
|
+
#Brazil Jun/2007
|
|
6
|
+
#
|
|
7
|
+
#Copyright (c) 2007-2008 Shairon Toledo
|
|
8
|
+
#
|
|
9
|
+
#Permission is hereby granted, free of charge, to any person
|
|
10
|
+
#obtaining a copy of this software and associated documentation
|
|
11
|
+
#files (the "Software"), to deal in the Software without
|
|
12
|
+
#restriction, including without limitation the rights to use,
|
|
13
|
+
#copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
#copies of the Software, and to permit persons to whom the
|
|
15
|
+
#Software is furnished to do so, subject to the following
|
|
16
|
+
#conditions:
|
|
17
|
+
#
|
|
18
|
+
#The above copyright notice and this permission notice shall be
|
|
19
|
+
#included in all copies or substantial portions of the Software.
|
|
20
|
+
#
|
|
21
|
+
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
22
|
+
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
23
|
+
#OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
24
|
+
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
25
|
+
#HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
26
|
+
#WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
27
|
+
#FROM, OUT OF OR IN CONNECTION WITH
|
|
28
|
+
|
|
29
|
+
require 'rghost/ps_object'
|
|
30
|
+
require 'rghost/ps_facade'
|
|
31
|
+
require 'rghost/document_callback_facade'
|
|
32
|
+
require 'rghost/virtual_pages'
|
|
33
|
+
require 'rghost/variable'
|
|
34
|
+
require 'rghost/pdf_security'
|
|
35
|
+
#The Document class child of PsFacade is used to join postscript objects to generate output file.
|
|
36
|
+
|
|
37
|
+
class RGhost::Document < RGhost::PsFacade
|
|
38
|
+
attr_reader :additional_params
|
|
39
|
+
include RGhost::DocumentCallbackFacade
|
|
40
|
+
include RGhost::RubyToPs
|
|
41
|
+
DISABLE_VIRTUAL_PAGE=RGhost::Variable.new(:has_vp?, false)
|
|
42
|
+
ENABLE_VIRTUAL_PAGE=RGhost::Variable.new(:has_vp?, true)
|
|
43
|
+
DEFAULT_OPTIONS={
|
|
44
|
+
:rows_per_page => 80 ,
|
|
45
|
+
:count_pages => 10,
|
|
46
|
+
:row_height => 0.4,
|
|
47
|
+
:row_padding => 0.1,
|
|
48
|
+
:font_encoding=> RGhost::Config::GS[:font_encoding],
|
|
49
|
+
:paper => RGhost::Paper::DEFAULT_OPTIONS
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#===Examples
|
|
53
|
+
#Creating document with 80 rows per page and custom paper
|
|
54
|
+
# doc=Document.new :rows_per_page => 80, paper => [30,5]
|
|
55
|
+
#Document A4 with row height 0.5 and font encoding CodePage1252
|
|
56
|
+
# doc=Document.new :row_height => 0.5, :font_encoding => 'CodePage1252'
|
|
57
|
+
#Defining all margins
|
|
58
|
+
# doc=Document.new :margin => 0.5
|
|
59
|
+
#
|
|
60
|
+
#
|
|
61
|
+
#==Parameters
|
|
62
|
+
#* <tt>:paper</tt> - Facade to +paper+ defined on the construction of Paper class
|
|
63
|
+
#* <tt>:margin, :duplex and :tuble</tt> - Facade to +options+ defined on the construction of Paper class
|
|
64
|
+
#* <tt>:rows_per_page</tt> - Specifies count of rows per pages.
|
|
65
|
+
#* <tt>:landscape</tt> - Whether true invert de size(width per height)
|
|
66
|
+
#* <tt>:count_pages</tt> - Defines postscript internal variable to display with class TextIn. Example:
|
|
67
|
+
#
|
|
68
|
+
# doc=Document.new :count_pages => 10
|
|
69
|
+
# doc.before_page_create :except => 1 do |b|
|
|
70
|
+
# b.text_in :x => 15, :y => 5, :write => "Page %current_page% of %count_pages%"
|
|
71
|
+
# end
|
|
72
|
+
#
|
|
73
|
+
#The value above %count_pages% will be evaluated inside of document for all pages except page one.
|
|
74
|
+
#* <tt>:fontsize</tt> - Defines the size of tag :default_font.
|
|
75
|
+
#* <tt>:row_height and row_padding</tt> - Its names say by itself :)
|
|
76
|
+
#* <tt>:font_encoding</tt> - Specifies encoding of data input. You can look for supported encoding using the method RGhost::Config.encode_test
|
|
77
|
+
def initialize(options={},&block)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@head,@callbacks=RGhost::PsObject.new,RGhost::PsObject.new
|
|
81
|
+
@head.set RGhost::Load.library(:type)
|
|
82
|
+
@head.set RGhost::Load.library(:unit)
|
|
83
|
+
#super()
|
|
84
|
+
@variables=DEFAULT_OPTIONS.dup.merge(options)
|
|
85
|
+
default_encoding
|
|
86
|
+
@paper=RGhost::Paper.new(options[:paper] || :A4, options)
|
|
87
|
+
@head.set @paper
|
|
88
|
+
@done=false
|
|
89
|
+
@docinfo={:Producer => "Ruby Ghostscript - RGhost v#{RGhost::VERSION::STRING}" }
|
|
90
|
+
@defines=[]
|
|
91
|
+
@additional_params=[]
|
|
92
|
+
|
|
93
|
+
default_variables
|
|
94
|
+
super()
|
|
95
|
+
#block.call(self) if block
|
|
96
|
+
#yield self if block
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def gs_paper #:nodoc:
|
|
100
|
+
@paper.gs_paper
|
|
101
|
+
end
|
|
102
|
+
#
|
|
103
|
+
|
|
104
|
+
#Creates map of tags if will be use in 'writable' classes(Show, Text, TextIn and TextArea).
|
|
105
|
+
#The font names file catalog can be generated by code below
|
|
106
|
+
# RGhost::Config.enviroment_fonts.render :pdf, :filename => "mycatalog.pdf"
|
|
107
|
+
#this can take while. If waiting for much time you has any font with problem, remove some fonts mostly international fonts not used often.
|
|
108
|
+
#Below little piece of catalog
|
|
109
|
+
#link:images/font_catalog.png
|
|
110
|
+
#
|
|
111
|
+
#After genereted catalog you can map your tags.
|
|
112
|
+
#
|
|
113
|
+
#
|
|
114
|
+
#Tags has +name+ of tag(as Symbol) and its options. The options are
|
|
115
|
+
#
|
|
116
|
+
#* <tt>:name</tt> - Font name from catalog.
|
|
117
|
+
#* <tt>:size</tt> - Font size.
|
|
118
|
+
#* <tt>:color</tt> - Color.create facade
|
|
119
|
+
#* <tt>:encoding</tt> - If true the font will be encoding using de pattern :font_encoding of the document.
|
|
120
|
+
#* <tt>:from</tt> - Load True Type or Type1 font from file.
|
|
121
|
+
#===Examples
|
|
122
|
+
# d=Document.new :encoding => 'IsoLatin'
|
|
123
|
+
# d.define_tags do
|
|
124
|
+
# tag :my_italic, :name => 'Hershey-Gothic-Italian-Oblique', :size => 10
|
|
125
|
+
# tag :myfont, :name => 'Hershey-Plain'
|
|
126
|
+
# tag :font_encoded, :name => 'NimbusMonL-Regu', :size => 8, :color => 0.5, :encoding => true
|
|
127
|
+
# tag :other_font, :name => 'NimbusMonL-Regu', :size => 10
|
|
128
|
+
# tag :arial, :name => 'Arial-ItalicMT', :color => '#ADAD66'
|
|
129
|
+
# tag :arial_bold, :name => 'NimbusSanL-BoldItal',:size => 12, :color => '#ADAD66'
|
|
130
|
+
# tag :monaco, :name => 'Monaco', :from => "/path/to/myfont.ttf", :size => 12
|
|
131
|
+
# end
|
|
132
|
+
#You can use :default_font tag for custom the default font.
|
|
133
|
+
#===Using tags
|
|
134
|
+
#====With Show class
|
|
135
|
+
# doc.show 'My Text on this row', :with => :my_italic, :align => :page_center
|
|
136
|
+
#====With Show class overrinding tag's color.
|
|
137
|
+
# doc.show 'My Text on this row', :with => :my_italic, :align => :page_center, :color => :red
|
|
138
|
+
#====With TextIn class.
|
|
139
|
+
# doc.text_in :x=> 3, :y=> 10, :tag => :arial_bold , :write => "Here's point(3,10)"
|
|
140
|
+
#====With Text
|
|
141
|
+
# doc.text '<myfont>My Text</myfont>on this row.<arial>Other text</arial><my_italic>Italic font</my_italic>'
|
|
142
|
+
#====With TextArea
|
|
143
|
+
# txt='<myfont>My Text</myfont>on this row.<arial>Other text</arial><my_italic>Italic font</my_italic>'
|
|
144
|
+
# doc.text_area txt, :text_align => :center, :width => 5, :x => 3, :y => 10
|
|
145
|
+
#====Using tag
|
|
146
|
+
# doc.use_tag :myfont
|
|
147
|
+
# doc.show "Simple Text", :tag => nil # it will use :myfont
|
|
148
|
+
# doc.show "Simple Text2", :tag => nil # it will use :myfont too
|
|
149
|
+
def define_tags(&block)
|
|
150
|
+
RGhost::Config::FONTMAP.instance_eval(&block)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def ps #:nodoc:
|
|
154
|
+
done
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
out=RGhost::PsObject.new
|
|
159
|
+
out.set @head
|
|
160
|
+
out.raw formated_docinfo
|
|
161
|
+
out.set @default_variables
|
|
162
|
+
out.set RGhost::Load.rg_enviroment
|
|
163
|
+
out.raw @defines.join
|
|
164
|
+
out.set RGhost::Cursor.moveto
|
|
165
|
+
out.set RGhost::Config::FONTMAP
|
|
166
|
+
out.set @callbacks
|
|
167
|
+
out.set RGhost::Load.library(:begin_document)
|
|
168
|
+
RGhost::Config::GS[:preload].uniq.each{|v| out.set RGhost::Load.library(v) }
|
|
169
|
+
out.set RGhost::Cursor.moveto
|
|
170
|
+
out.raw super
|
|
171
|
+
out.raw "\n\n"
|
|
172
|
+
|
|
173
|
+
"#{out} "
|
|
174
|
+
|
|
175
|
+
#"#{@head} \n%%endhead\n#{@default_variables}\n\n #{Load.rg_enviroment} #{@defines.join} #{@callbacks} #{Load.library(:begin_document)}\n #{Cursor.moveto}#{super}"
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
end
|
|
179
|
+
# def link(label,options={:to => 'http://rghost.rubyforge.net'})
|
|
180
|
+
# raw "/:link_str #{to_string(label)} def /:link_uri #{to_string(options[:to])} def :link_make"
|
|
181
|
+
#
|
|
182
|
+
# end
|
|
183
|
+
#Facade to RubyGhostEngine.render
|
|
184
|
+
#Converts a document to an output format, such as :pdf, :png, :ps, :jpeg, :tiff etc
|
|
185
|
+
#The paramter device can be found at RGhost::Constants::Devices or at http://pages.cs.wisc.edu/~ghost/doc/cvs/Devices.htm
|
|
186
|
+
#===Options
|
|
187
|
+
#Method render have the following options available.
|
|
188
|
+
#* <tt>:filename</tt> - File path.
|
|
189
|
+
#* <tt>:logfile</tt> - Writes the converter's process into a file.
|
|
190
|
+
#* <tt>:multipage</tt> - Whether true the output will be one page per file posfixed by _0001.ext, for example, for one file name 'test.png' with two pages will create test_001.png and test_002.png
|
|
191
|
+
#* <tt>:resolution</tt> - Integer value to output resolution.
|
|
192
|
+
#* <tt>:quality</tt> - Presets the "distiller parameters" to one of four predefined settings:
|
|
193
|
+
# :screen - selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
|
|
194
|
+
# :ebook - selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
|
|
195
|
+
# :printer - selects output similar to the Acrobat Distiller "Print Optimized" setting.
|
|
196
|
+
# :prepress - selects output similar to Acrobat Distiller "Prepress Optimized" setting.
|
|
197
|
+
# :default - selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.
|
|
198
|
+
#* <tt>:size</tt> - Crops a single page using a string of dimension, example, '200x180', '140x90'.
|
|
199
|
+
#* <tt>:range</tt> - Specifies range of pages(PDF only)
|
|
200
|
+
#====Ghostscript interpreter options
|
|
201
|
+
#
|
|
202
|
+
#Array of Hashes for Ghostscript interpreter look at http://pages.cs.wisc.edu/~ghost/doc/cvs/Use.htm#Parameter_switches for more details.
|
|
203
|
+
#You can use two parameter :s and :d, examples
|
|
204
|
+
# :s => [{:GenericResourceDir => /dir, :DEFAULTPAPERSIZE=> "a3"}]
|
|
205
|
+
# :d => [ {:TextAlphaBits => 2} ]
|
|
206
|
+
#Or one string using the parameter :raw, as below
|
|
207
|
+
# :raw => "-sGenericResourceDir=/test -dTextAlphaBits=2"
|
|
208
|
+
#
|
|
209
|
+
#===Examples
|
|
210
|
+
# doc=Document.new
|
|
211
|
+
# #do something
|
|
212
|
+
#
|
|
213
|
+
# doc.render :pdf, :filename => 'foo.pdf # PDF output
|
|
214
|
+
# doc.render :pdf, :filename => 'foo.pdf, :quality => :ebook # PDF output
|
|
215
|
+
# doc.render :jpeg, :filename => 'foo.jpg' # JPEG output
|
|
216
|
+
# doc.render :png, :filename => 'foo.png', :multipage => true # PNG output one page per file
|
|
217
|
+
# doc.render :tiff, :filename => 'foo.tiff', :resolution => 300 # TIFF with 300dpi
|
|
218
|
+
# doc.render :ps, :raw => '-sFONTMAP=/var/myoptional/font/map', :filename => 'test.ps'
|
|
219
|
+
#
|
|
220
|
+
#===Testing if has errors
|
|
221
|
+
# doc=Document.new
|
|
222
|
+
# doc.raw "hahahah!" #it produce error in ps stack
|
|
223
|
+
# doc.render :jpeg, :filename => 'with_error.jpg'
|
|
224
|
+
# puts r.errors if r.error? #=> GPL Ghostscript 8.61: Unrecoverable error, exit code 1.\ Error: /undefined in hahahah!
|
|
225
|
+
#
|
|
226
|
+
#===Printing
|
|
227
|
+
#====Using printing system
|
|
228
|
+
# doc=Document.new
|
|
229
|
+
# #do something
|
|
230
|
+
# f="myjob.prn"
|
|
231
|
+
# doc.render :laserjet, :filename => f
|
|
232
|
+
# `lpr #{f}`
|
|
233
|
+
#====Windows shared printer
|
|
234
|
+
# doc.render :eps9mid, :filename => "//machine/printer"
|
|
235
|
+
def render(device,options={})
|
|
236
|
+
rg=RGhost::Engine.new(self,options)
|
|
237
|
+
rg.render(device)
|
|
238
|
+
rg
|
|
239
|
+
end
|
|
240
|
+
#Behavior as render but returns content file after convertion.
|
|
241
|
+
#===Example with Rails
|
|
242
|
+
# def my_action
|
|
243
|
+
# doc=RGhost::Document.new
|
|
244
|
+
# #do something
|
|
245
|
+
# send_data doc.render_stream(:pdf), :filename => "/tmp/myReport.pdf"
|
|
246
|
+
# end
|
|
247
|
+
#
|
|
248
|
+
#===TCP/IP direct printer
|
|
249
|
+
# require 'socket'
|
|
250
|
+
#
|
|
251
|
+
# doc=Document.new
|
|
252
|
+
# #do something
|
|
253
|
+
# printer = TCPSocket.open('192.168.1.70', 9100)
|
|
254
|
+
# printer.write doc.render_stream(:ps)
|
|
255
|
+
# printer.close
|
|
256
|
+
def render_stream(device,options={})
|
|
257
|
+
rg=render(device,options)
|
|
258
|
+
out=rg.output.readlines.join
|
|
259
|
+
rg.clear_output
|
|
260
|
+
out
|
|
261
|
+
end
|
|
262
|
+
#Facade to Function.new
|
|
263
|
+
#Defines low level function to optimize repetitive piece of code.
|
|
264
|
+
#===Example
|
|
265
|
+
# doc=Document.new
|
|
266
|
+
# doc.define :piece do
|
|
267
|
+
# set Show.new("Hello")
|
|
268
|
+
# set Cursor.next_row
|
|
269
|
+
# set HorizontalLine.new(:middle)
|
|
270
|
+
# set Cursor.next_row
|
|
271
|
+
# end
|
|
272
|
+
# #Repeting ten times the same code
|
|
273
|
+
# 10.times{ doc.call :piece }
|
|
274
|
+
def define(name,&block)
|
|
275
|
+
@defines << RGhost::Function.new("_#{name}",&block)
|
|
276
|
+
end
|
|
277
|
+
def define_variable(name,value)
|
|
278
|
+
set RGhost::Variable.new(name,value)
|
|
279
|
+
end
|
|
280
|
+
#Defines a function using the method define after that call de function one time.
|
|
281
|
+
def define_and_call(name,&block)
|
|
282
|
+
define(name,&block)
|
|
283
|
+
call(name)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
#Prints the text file using the predefined tag +:pre+
|
|
287
|
+
#===Example
|
|
288
|
+
# doc=Document.new :paper => :A4, :landscape => true
|
|
289
|
+
# doc.print_file "/etc/passwd"
|
|
290
|
+
# doc.render :pdf, :filename => "/tmp/passwd.pdf
|
|
291
|
+
def print_file(file)
|
|
292
|
+
s=File.open(file).readlines.join.gsub(/</,'<').gsub(/>/,'>').gsub(/\n/,'<br/>')
|
|
293
|
+
|
|
294
|
+
use_tag :pre
|
|
295
|
+
set RGhost::Text.new(s,true)
|
|
296
|
+
|
|
297
|
+
end
|
|
298
|
+
#With method virtual_pages you can define any virtual pages per physical page.
|
|
299
|
+
#The cursor into virtual page jumps in column for each virtual page and run primitives next_page when ends columns. Look the example below.
|
|
300
|
+
#Example for a document without virtual pages we will has
|
|
301
|
+
# doc=Document.new
|
|
302
|
+
# doc.text File.readlines("/tmp/mytext.txt")
|
|
303
|
+
#will generate
|
|
304
|
+
#
|
|
305
|
+
#link:images/virtual_page1.png
|
|
306
|
+
#
|
|
307
|
+
#Now for a document with 3 virtual pages
|
|
308
|
+
# doc=Document.new
|
|
309
|
+
# doc.virtual_pages do
|
|
310
|
+
# new_page :width => 4
|
|
311
|
+
# new_page :width => 7, :margin_left => 1
|
|
312
|
+
# new_page :width => 4, :margin_left => 1
|
|
313
|
+
# end
|
|
314
|
+
# doc.text File.readlines("/tmp/mytext.txt")
|
|
315
|
+
#will generate
|
|
316
|
+
#
|
|
317
|
+
#link:images/virtual_page2.png
|
|
318
|
+
#
|
|
319
|
+
#PS: The parameter margin left of first virtual page won't be used because it's will use page's margin left.
|
|
320
|
+
def virtual_pages(&block)
|
|
321
|
+
set RGhost::VirtualPages.new(&block)
|
|
322
|
+
end
|
|
323
|
+
{
|
|
324
|
+
:base => -4,
|
|
325
|
+
:print => -4,
|
|
326
|
+
:modify => -8,
|
|
327
|
+
:copy => -16,
|
|
328
|
+
:annotate => -32,
|
|
329
|
+
:interactive => -256,
|
|
330
|
+
:copy_access => -512,
|
|
331
|
+
:assemble => -1024,
|
|
332
|
+
:high_quality_print => -2048,
|
|
333
|
+
:all => -3904}
|
|
334
|
+
|
|
335
|
+
#Security disable the permissions and define passwords to PDF documents.
|
|
336
|
+
#The password just support set of \w .
|
|
337
|
+
#Always that use the block security should set owner and user password. By default the encryption is 3.
|
|
338
|
+
#Document Security can be set with the permissions flags
|
|
339
|
+
#===Disable options
|
|
340
|
+
#* <tt>:base or :print</tt> Print document (possibly not at the highest quality level).
|
|
341
|
+
#* <tt>:modify</tt>Modify contents of document, except as controlled by :annotate, :interective and :assemble.
|
|
342
|
+
#* <tt>:copy</tt>Copy text and graphics from document other than that controlled by :copy_access
|
|
343
|
+
#* <tt>:annotate</tt>Add or modify text annotations, fill in interactive form fields, and if :interective is set, create or modify interactive form fields
|
|
344
|
+
#* <tt>:interactive</tt>Fill in existing interacive form fields, even if :annotate is clear
|
|
345
|
+
#* <tt>:copy_access</tt>Extract text and graphics (in support of accessibility to disabled users or for other purposes).
|
|
346
|
+
#* <tt>:assemble</tt>Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even when :base is clear
|
|
347
|
+
#* <tt>:high_quality_print</tt>Add or modify text annotations
|
|
348
|
+
#* <tt>:all</tt>Disable all permissions.
|
|
349
|
+
#===Example 1
|
|
350
|
+
# doc.security do |sec|
|
|
351
|
+
# sec.owner_password ="owner" #password without space!
|
|
352
|
+
# sec.user_password ="user" #password without space!
|
|
353
|
+
# sec.key_length = 128
|
|
354
|
+
# sec.disable :print, :copy, :high_quality
|
|
355
|
+
# end
|
|
356
|
+
#===Example 2
|
|
357
|
+
#Disable all
|
|
358
|
+
# doc.security do |sec|
|
|
359
|
+
# sec.owner_password ="owner" #password without space!
|
|
360
|
+
# sec.user_password ="user" #password without space!
|
|
361
|
+
# sec.disable :all
|
|
362
|
+
# end
|
|
363
|
+
#
|
|
364
|
+
def security
|
|
365
|
+
sec=RGhost::PdfSecurity.new
|
|
366
|
+
yield sec
|
|
367
|
+
@additional_params << sec.gs_params
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
#Starts and Ends internal benckmark will write in bottom of page.
|
|
371
|
+
#===Example
|
|
372
|
+
# doc=Document.new
|
|
373
|
+
# doc.benchmark :start
|
|
374
|
+
# doc.... #do something
|
|
375
|
+
# doc.benchmarck :stop
|
|
376
|
+
# doc.render ...
|
|
377
|
+
def benchmark(state=:start)
|
|
378
|
+
case state
|
|
379
|
+
when :stop
|
|
380
|
+
moveto(:x => "20", :y => "20")
|
|
381
|
+
raw %Q{
|
|
382
|
+
default_font (RGhost::Ghostscript benchmark: ) show
|
|
383
|
+
realtime benchmark sub 1000 div 20 string cvs show ( seconds ) show
|
|
384
|
+
}
|
|
385
|
+
when :start
|
|
386
|
+
set RGhost::Variable.new(:benchmark,"realtime")
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
|
|
390
|
+
#Rghost can make use of Encapsulated Postscript files to act as templates(EPS).
|
|
391
|
+
#This way you can create the visual layout of the page using a graphics tool and just paint the dynamic pieces over using Rghost.
|
|
392
|
+
#
|
|
393
|
+
#link:images/templates_demo.jpg
|
|
394
|
+
#
|
|
395
|
+
#Above we have mytemplate.eps that was generated by a graphic app, my_ruby_program.rb that takes care of the positioning and at last the generated output.
|
|
396
|
+
#
|
|
397
|
+
#
|
|
398
|
+
#A Template use example
|
|
399
|
+
#Let's say that the files first.eps and content.eps already exist. Now we shall see how to create a document that uses the template first.eps for the cover and the rest of the document uses content.eps.
|
|
400
|
+
#
|
|
401
|
+
# d = Document.new :margin_top => 5, :margin_bottom => 2
|
|
402
|
+
#
|
|
403
|
+
#Just for the first page
|
|
404
|
+
#
|
|
405
|
+
# d.first_page do
|
|
406
|
+
# image "/my/dir/first.eps" #loads the template
|
|
407
|
+
# text_in :x=> 5, :y=> 17, :text => "My Report", :with => :big
|
|
408
|
+
# next_page #go to the next page using cursors
|
|
409
|
+
# end
|
|
410
|
+
#Callback for all other pages.
|
|
411
|
+
#
|
|
412
|
+
# d.before_page_create :except => 1 do
|
|
413
|
+
# image "/my/dir/content.eps"
|
|
414
|
+
# text_in :text => "Page %current_page% of %count_pages%", :x => 18, :y => 27, :with => :normal
|
|
415
|
+
# end
|
|
416
|
+
#
|
|
417
|
+
#1500 rows
|
|
418
|
+
#
|
|
419
|
+
# 1500.times do |n|
|
|
420
|
+
# d.show "Value #{n}"
|
|
421
|
+
# d.next_row
|
|
422
|
+
# end
|
|
423
|
+
#We have a cover page and 1500 rows, judging by the margins each page supports 46 rows, so we have 1500/46 = 32.60 pages plus the cover. Rounding it up totals 34 pages for the :count_pages
|
|
424
|
+
#
|
|
425
|
+
# d.define_variable(:count_pages, 34)
|
|
426
|
+
# d.showpage
|
|
427
|
+
# d.render :pdf, :filename => "/tmp/test.pdf"
|
|
428
|
+
#
|
|
429
|
+
#If we knew the amount of pages beforehand we could state it on the creation of the document, i.e.
|
|
430
|
+
#
|
|
431
|
+
# :current_pages => 34
|
|
432
|
+
#
|
|
433
|
+
#The example uses one template per page, but this is not a limit in RGhost. You can have multiple images and templates on per page. Just have to define the template:
|
|
434
|
+
#
|
|
435
|
+
# d=Document.new :margin_top => 5, :margin_bottom => 2
|
|
436
|
+
# d.define_template(:myform, '/local/template/form1.eps', :x=> 3, :y => 5)
|
|
437
|
+
#
|
|
438
|
+
#and call it on the document.
|
|
439
|
+
# d.use_template :myform
|
|
440
|
+
#
|
|
441
|
+
#===Arguments
|
|
442
|
+
#* <tt>:name</tt> - Template's name.
|
|
443
|
+
#* <tt>:file_path</tt> - Path to file.
|
|
444
|
+
#* <tt>:options</tt> - Options facade to Image.for(or image)
|
|
445
|
+
def define_template(name,file_path,options={})
|
|
446
|
+
|
|
447
|
+
@defines << RGhost::Function.new("_#{name}",RGhost::Image.for(file_path,options))
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
#Informs is ready to converts/prints
|
|
452
|
+
def done
|
|
453
|
+
|
|
454
|
+
unless @done
|
|
455
|
+
@done=true
|
|
456
|
+
raw "\n\n"
|
|
457
|
+
call :after_page_create
|
|
458
|
+
call :callback
|
|
459
|
+
call :after_document_create
|
|
460
|
+
|
|
461
|
+
showpage
|
|
462
|
+
raw "\n%%EOF"
|
|
463
|
+
end
|
|
464
|
+
self
|
|
465
|
+
end
|
|
466
|
+
def enable_virtual_pages
|
|
467
|
+
set RGhost::Variable.new(:has_vp?, true)
|
|
468
|
+
|
|
469
|
+
end
|
|
470
|
+
def disable_virtual_pages
|
|
471
|
+
set RGhost::Variable.new(:has_vp?, false)
|
|
472
|
+
set RGhost::Variable.new(:limit_left, 'source_limit_left')
|
|
473
|
+
set RGhost::Variable.new(:limit_right, 'source_limit_right')
|
|
474
|
+
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
#Configures properties about your document.
|
|
478
|
+
#The keys are supported :Creator, :Title, :Author, :Subject and :Keywords, or downcase as :title etc.
|
|
479
|
+
#Example:
|
|
480
|
+
# doc.properties :Autor => "Shairon Toledo", :Title => "Learning RGhost"
|
|
481
|
+
def info(docinfo={})
|
|
482
|
+
#puts docinfo.inspect
|
|
483
|
+
@docinfo.merge!(docinfo)
|
|
484
|
+
#puts @docinfo.inspect
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
#Creates Grid::Rails inside of the document. Facade to RGhost::Grid::Rails
|
|
488
|
+
def rails_grid(default_columns_options={})
|
|
489
|
+
|
|
490
|
+
grid=RGhost::Grid::Rails.new(default_columns_options)
|
|
491
|
+
yield grid
|
|
492
|
+
grid.style(default_columns_options[:style]) if default_columns_options[:style]
|
|
493
|
+
grid.data(default_columns_options[:data]) if default_columns_options[:data]
|
|
494
|
+
set grid
|
|
495
|
+
|
|
496
|
+
end
|
|
497
|
+
#Creates Grid::CSV inside of the document. Facade to RGhost::Grid::CSV
|
|
498
|
+
def csv_grid(default_columns_options={})
|
|
499
|
+
grid=RGhost::Grid::CSV.new(default_columns_options)
|
|
500
|
+
yield grid
|
|
501
|
+
grid.style(default_columns_options[:style]) if default_columns_options[:style]
|
|
502
|
+
grid.data(default_columns_options[:data]) if default_columns_options[:data]
|
|
503
|
+
set grid
|
|
504
|
+
end
|
|
505
|
+
#Creates Grid::Matrix inside of the document. Facade to RGhost::Grid::Matrix
|
|
506
|
+
def matrix_grid(default_columns_options={})
|
|
507
|
+
grid=RGhost::Grid::Matrix.new(default_columns_options)
|
|
508
|
+
yield grid
|
|
509
|
+
grid.style(default_columns_options[:style]) if default_columns_options[:style]
|
|
510
|
+
set grid
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
private
|
|
515
|
+
|
|
516
|
+
def default_variables
|
|
517
|
+
ps=RGhost::PsObject.new
|
|
518
|
+
ps.set RGhost::Variable.new(:rows_per_page,@variables[:rows_per_page])
|
|
519
|
+
ps.set RGhost::Variable.new(:count_pages,@variables[:count_pages])
|
|
520
|
+
ps.set RGhost::Variable.new(:row_height,RGhost::Units::parse(@variables[:row_height]))
|
|
521
|
+
ps.set RGhost::Variable.new(:row_padding,RGhost::Units::parse(@variables[:row_padding]))
|
|
522
|
+
|
|
523
|
+
@default_variables=ps
|
|
524
|
+
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
def default_encoding
|
|
528
|
+
@head.set RGhost::Load.library(@variables[:font_encoding],:enc)
|
|
529
|
+
@head.set RGhost::Variable.new(:default_encoding,@variables[:font_encoding])
|
|
530
|
+
|
|
531
|
+
end
|
|
532
|
+
def formated_docinfo
|
|
533
|
+
d=["["]
|
|
534
|
+
|
|
535
|
+
@docinfo.each do |k,v|
|
|
536
|
+
d << "/#{k.to_s.capitalize}"
|
|
537
|
+
d << to_string(v)
|
|
538
|
+
end
|
|
539
|
+
d << "/DOCINFO"
|
|
540
|
+
d << "pdfmark "
|
|
541
|
+
d.join(" ")
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
|