Module: HexaPDF::DictionaryFields::PDFByteStringConverter

Defined in:
lib/hexapdf/dictionary_fields.rb

Overview

Converter module for binary string fields to automatically convert a string into binary encoding.

See: PDF2.0 s7.9.2.4

Class Method Summary collapse

Class Method Details

.additional_typesObject

:nodoc:



291
292
293
# File 'lib/hexapdf/dictionary_fields.rb', line 291

def self.additional_types
  String
end

.convert(str, _type, _document) ⇒ Object

Converts the string into binary encoding, assuming it is a non-binary string. Otherwise returns nil.



297
298
299
300
# File 'lib/hexapdf/dictionary_fields.rb', line 297

def self.convert(str, _type, _document)
  return if !str.kind_of?(String) || str.encoding == Encoding::BINARY
  str.dup.force_encoding(Encoding::BINARY)
end

.usable_for?(type) ⇒ Boolean

This converter is usable if the type is PDFByteString.

Returns:



286
287
288
# File 'lib/hexapdf/dictionary_fields.rb', line 286

def self.usable_for?(type)
  type == PDFByteString
end