Class: Prune::Document
- Inherits:
-
Object
- Object
- Prune::Document
- Defined in:
- lib/prune/document.rb
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
Returns the value of attribute catalog.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#fonts ⇒ Object
readonly
Returns the value of attribute fonts.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#outlines ⇒ Object
readonly
Returns the value of attribute outlines.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#proc_set ⇒ Object
readonly
Returns the value of attribute proc_set.
-
#version ⇒ Object
writeonly
Sets the attribute version.
Instance Method Summary collapse
-
#initialize ⇒ Document
constructor
Initialize.
-
#save_as(filename) ⇒ Object
Save pdf document to a file.
-
#to_s ⇒ Object
Convert to String.
Methods included from PObjects
Constructor Details
#initialize ⇒ Document
Initialize
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/prune/document.rb', line 15 def initialize @elements = [] @fonts = {} @version = "1.2" # Initialize PDF infos. @info = Info.new(self) # Initialize catalog. @catalog = Catalog.new(self) @catalog.version = @version # Initialize outlines. outlines = Outlines.new(self) @catalog.outlines = outlines.reference # Initialize pages. @pages = Pages.new(self) @catalog.pages = @pages.reference # Initialize ProcSet @proc_set = Elements::ProcedureSets.new(self) end |
Instance Attribute Details
#catalog ⇒ Object (readonly)
Returns the value of attribute catalog.
10 11 12 |
# File 'lib/prune/document.rb', line 10 def catalog @catalog end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
11 12 13 |
# File 'lib/prune/document.rb', line 11 def elements @elements end |
#fonts ⇒ Object (readonly)
Returns the value of attribute fonts.
11 12 13 |
# File 'lib/prune/document.rb', line 11 def fonts @fonts end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
10 11 12 |
# File 'lib/prune/document.rb', line 10 def info @info end |
#outlines ⇒ Object (readonly)
Returns the value of attribute outlines.
10 11 12 |
# File 'lib/prune/document.rb', line 10 def outlines @outlines end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
10 11 12 |
# File 'lib/prune/document.rb', line 10 def pages @pages end |
#proc_set ⇒ Object (readonly)
Returns the value of attribute proc_set.
10 11 12 |
# File 'lib/prune/document.rb', line 10 def proc_set @proc_set end |
#version=(value) ⇒ Object (writeonly)
Sets the attribute version
12 13 14 |
# File 'lib/prune/document.rb', line 12 def version=(value) @version = value end |
Instance Method Details
#save_as(filename) ⇒ Object
Save pdf document to a file.
40 41 42 43 44 45 46 47 48 |
# File 'lib/prune/document.rb', line 40 def save_as(filename) raise DocumentEmptyError if @pages.empty? # Write to a file File.open(filename, "wb") do |file| file.flock(File::LOCK_EX) file.write(self.to_s) file.flock(File::LOCK_UN) end end |
#to_s ⇒ Object
Convert to String.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/prune/document.rb', line 51 def to_s # Write header out = [] out << "%PDF-#{@version}" out << "%" + [0xE2, 0xE3, 0xCF, 0xD3].pack("c*") # Write objects out += @elements.collect{|element| element.to_s} # Write cross-reference table out += cross_reference_table(@elements.size, out.join(LF)) # Write trailer out += trailer(out.join(LF)) out << "%%EOF" out.join(LF) end |