Class: RPDF::PDFObject
- Inherits:
-
Object
- Object
- RPDF::PDFObject
- Defined in:
- lib/rpdf/pdfobject.rb
Overview
An object which is a part of a PDF document. [PDFRef15 p27]
Direct Known Subclasses
PDFArray, PDFBoolean, PDFDictionary, PDFName, PDFNull, PDFNumeric, PDFStream, PDFString
Instance Attribute Summary collapse
-
#generation_number ⇒ Object
readonly
Returns the value of attribute generation_number.
-
#object_number ⇒ Object
readonly
Returns the value of attribute object_number.
Instance Method Summary collapse
- #indirect? ⇒ Boolean
-
#initialize(document = nil) ⇒ PDFObject
constructor
Make an indirect object if a document is passed, otherwise a direct object.
-
#invalidate ⇒ Object
Subclasses has to call this in their invalidate method if they override it.
-
#invalidated? ⇒ Boolean
true if the object has already been written to the PDF stream.
-
#to_pdf ⇒ Object
Return a representation suitable to write to a PDF file [PDFRef15 p39].
-
#to_ref ⇒ Object
Return an indirect reference to this object if it’s indirect, return the bytestream otherwise.
Constructor Details
#initialize(document = nil) ⇒ PDFObject
Make an indirect object if a document is passed, otherwise a direct object.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rpdf/pdfobject.rb', line 9 def initialize(document=nil) if document @object_number = document.new_id(self) @document = document else @object_number = 0 # The object number of an indirect object should be positive end @generation_number = 0 @invalidated = false end |
Instance Attribute Details
#generation_number ⇒ Object (readonly)
Returns the value of attribute generation_number.
6 7 8 |
# File 'lib/rpdf/pdfobject.rb', line 6 def generation_number @generation_number end |
#object_number ⇒ Object (readonly)
Returns the value of attribute object_number.
6 7 8 |
# File 'lib/rpdf/pdfobject.rb', line 6 def object_number @object_number end |
Instance Method Details
#indirect? ⇒ Boolean
20 21 22 |
# File 'lib/rpdf/pdfobject.rb', line 20 def indirect? @object_number > 0 end |
#invalidate ⇒ Object
Subclasses has to call this in their invalidate method if they override it
25 26 27 28 |
# File 'lib/rpdf/pdfobject.rb', line 25 def invalidate @document.write(self) @invalidated = true end |
#invalidated? ⇒ Boolean
true if the object has already been written to the PDF stream
31 32 33 |
# File 'lib/rpdf/pdfobject.rb', line 31 def invalidated? @invalidated end |
#to_pdf ⇒ Object
Return a representation suitable to write to a PDF file
- PDFRef15 p39
37 38 39 40 41 42 43 44 45 |
# File 'lib/rpdf/pdfobject.rb', line 37 def to_pdf if indirect? bytes = "#{@object_number} #{@generation_number} obj\n" bytes << to_s << "\n" bytes << "endobj\n\n" else to_s end end |
#to_ref ⇒ Object
Return an indirect reference to this object if it’s indirect, return the bytestream otherwise.
- PDFRef15 p39
50 51 52 53 54 55 56 |
# File 'lib/rpdf/pdfobject.rb', line 50 def to_ref if indirect? "#{@object_number} #{@generation_number} R" else to_s end end |