Class: Origami::PDF::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/origami/header.rb

Overview

Class representing a PDF Header.

Constant Summary collapse

MINVERSION =
0
MAXVERSION =
7
MAGIC =
/%PDF-(\d+)\.(\d+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(majorversion = 1, minorversion = 4) ⇒ Header

Creates a file header, with the given major and minor versions.

majorversion

Major PDF version, must be 1.

minorversion

Minor PDF version, must be between 0 and 7.



50
51
52
53
54
55
56
57
# File 'lib/origami/header.rb', line 50

def initialize(majorversion = 1, minorversion = 4)

  #if majorversion.to_i != 1 || ! ((MINVERSION..MAXVERSION) === minorversion.to_i)
  #  Console.colorprint("[info ] Warning: Invalid file version : #{majorversion}.#{minorversion}\n", Console::Colors::YELLOW, false, STDERR) 
  #end

  @majorversion, @minorversion = majorversion, minorversion
end

Instance Attribute Details

#majorversionObject

Returns the value of attribute majorversion.



43
44
45
# File 'lib/origami/header.rb', line 43

def majorversion
  @majorversion
end

#minorversionObject

Returns the value of attribute minorversion.



43
44
45
# File 'lib/origami/header.rb', line 43

def minorversion
  @minorversion
end

Class Method Details

.parse(stream) ⇒ Object

:nodoc:



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/origami/header.rb', line 59

def self.parse(stream) #:nodoc:

  if not stream.scan(MAGIC).nil?
    maj = stream[1].to_i
    min = stream[2].to_i
  else
    raise InvalidHeaderError, "Invalid header format : #{stream.peek(15).inspect}"
  end
     
  PDF::Header.new(maj,min)
end

Instance Method Details

#to_fObject

:nodoc:



82
83
84
# File 'lib/origami/header.rb', line 82

def to_f #:nodoc:
  to_sym.to_s.to_f
end

#to_sObject

Outputs self into PDF code.



74
75
76
# File 'lib/origami/header.rb', line 74

def to_s
  "%PDF-#{@majorversion}.#{@minorversion}" + EOL
end

#to_symObject

:nodoc:



78
79
80
# File 'lib/origami/header.rb', line 78

def to_sym #:nodoc:
  "#{@majorversion}.#{@minorversion}".to_sym
end