Class: DPTM6::PDF::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/dptm6/pdf.rb

Direct Known Subclasses

PageObject, ResourceObject, StreamObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf, num) ⇒ Object

Returns a new instance of Object.



134
135
136
137
138
# File 'lib/dptm6/pdf.rb', line 134

def initialize(pdf, num)
  @pdf = pdf
  @num = num
  read
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



132
133
134
# File 'lib/dptm6/pdf.rb', line 132

def data
  @data
end

#numObject (readonly)

Returns the value of attribute num.



131
132
133
# File 'lib/dptm6/pdf.rb', line 131

def num
  @num
end

#pdfObject (readonly)

Returns the value of attribute pdf.



131
132
133
# File 'lib/dptm6/pdf.rb', line 131

def pdf
  @pdf
end

Instance Method Details

#move_to(pdf, num) ⇒ Object



146
147
148
149
150
# File 'lib/dptm6/pdf.rb', line 146

def move_to(pdf, num)
  @pdf = pdf
  @num = num
  self
end

#replace_pagenum(hash) ⇒ Object



160
161
162
163
164
# File 'lib/dptm6/pdf.rb', line 160

def replace_pagenum(hash)
  hash.each do |key,num|
    @data[/#{key}\s++(\d++)\s++\d++\s++R/,1] = num.to_s
  end
end

#to_stringObject



140
141
142
143
144
# File 'lib/dptm6/pdf.rb', line 140

def to_string
  return @data if (@num == 0 && @data =~ /%PDF/)

  "#{@num} #{0} obj\n" << @data << "endobj\n"
end

#writeObject



152
153
154
155
156
157
158
# File 'lib/dptm6/pdf.rb', line 152

def write
  fp = @pdf.fp
  pos = fp.pos
  fp.write(to_string)
  len = fp.pos - pos
  @pdf.xref << [pos, len, @num]
end