Class: PDF::Writer::Object::Info

Inherits:
PDF::Writer::Object show all
Defined in:
lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/info.rb

Overview

Define the document information – metadata.

Constant Summary collapse

Info =
%w{CreationDate Creator Title Author Subject Keywords ModDate Trapped Producer}

Instance Attribute Summary

Attributes inherited from PDF::Writer::Object

#oid

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Info

Returns a new instance of Info.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/info.rb', line 14

def initialize(parent)
  super(parent)

  @parent.instance_variable_set('@info', self)
  @creationdate = Time.now

  @creator  = File.basename($0)
  @producer = "PDF::Writer for Ruby"
  @title    = nil
  @author   = nil
  @subject  = nil
  @keywords = nil
  @moddate  = nil
  @trapped  = nil
end

Instance Method Details

#to_sObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/info.rb', line 34

def to_s
  res = "\n#{@oid} 0 obj\n<<\n"
  Info.each do |i|
    v = __send__("#{i.downcase}".intern)
    next if v.nil?
    res << "/#{i} ("
    if v.kind_of?(Time)
      s = "D:%04d%02d%02d%02d%02d"
      v = v.utc
      v = s % [ v.year, v.month, v.day, v.hour, v.min ]
    end

    res << PDF::Writer.escape(v)
    res << ")\n"
  end
  res << ">>\nendobj"
end