Method: PDF::Info#command

Defined in:
lib/pdf/info.rb

#commandObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pdf/info.rb', line 20

def command
  output = `#{self.class.command_path} -enc UTF-8 -f 1 -l -1 "#{@pdf_path}" 2> /dev/null`
  exit_code = $?
  case exit_code
  when 0 || nil
    if !output.valid_encoding?
      # It's already UTF-8, so we need to convert to UTF-16 and back to
      # force the bad characters to be replaced.
      output.encode!('UTF-16', :undef => :replace, :invalid => :replace, :replace => "")
      output.encode!('UTF-8')
    end
    return output
  else
    exit_error = PDF::Info::UnexpectedExitError.new
    exit_error.exit_code = exit_code
    raise exit_error
  end
end