Module: Okab::PDF::Encoding

Defined in:
lib/okab/pdf/writer.rb

Class Method Summary collapse

Class Method Details

.hex(bytes) ⇒ Object



53
# File 'lib/okab/pdf/writer.rb', line 53

def hex(bytes) = "<#{bytes.b.unpack1('H*')}>"

.name(value) ⇒ Object



66
67
68
# File 'lib/okab/pdf/writer.rb', line 66

def name(value)
  value.to_s.b.gsub(/[^A-Za-z0-9_.+-]/) { |byte| format("#%02X", byte.ord) }
end

.number(value) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
# File 'lib/okab/pdf/writer.rb', line 55

def number(value)
  number = value.to_f
  raise ArgumentError, "PDF numbers must be finite" unless number.finite?

  BigDecimal(number.to_s).to_s("F")
end

.unicode_hex(text) ⇒ Object



62
63
64
# File 'lib/okab/pdf/writer.rb', line 62

def unicode_hex(text)
  hex(text.encode(::Encoding::UTF_16BE).b)
end