Class: Poppler::Document

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/poppler/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Document

Returns a new instance of Document.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/poppler/document.rb', line 24

def initialize(*args)
  if args.size == 1 and args[0].is_a?(Hash)
    options = args[0]
  else
    uri_or_data, password = args
    if pdf_data?(uri_or_data)
      options = {
        :data => uri_or_data,
        :password => password
      }
    else
      options = {
        :uri => ensure_uri(uri_or_data),
        :password => password
      }
    end
  end

  data = options[:data]
  uri = options[:uri]
  path = options[:path]
  stream = options[:stream]
  length = options[:length]
  file = options[:file]
  password = options[:password]

  if data
    if respond_to?(:initialize_new_from_bytes)
      initialize_new_from_bytes(data, password)
    else
      @file = Tempfile.new(["poppler", ".pdf"])
      @file.binmode
      @file.write(data)
      @file.close
      initialize_new_from_file(ensure_uri(@file.path), password)
    end
  elsif uri
    initialize_new_from_file(uri, password)
  elsif path
    uri = ensure_uri(path)
    initialize_new_from_file(uri, password)
  elsif stream
    if length.nil?
      raise(ArgumentError,
            "must specify :length for :stream: #{options.inspect}")
    end
    initialize_new_from_stream(stream, length, password)
  elsif file
    case file
    when String, Pathname
      initialize(path: file, password: password)
    else
      initialize_new_from_gfile(file, password)
    end
  else
    message =
      "must specify one of :data, :uri, :path, :stream or :file: " +
      options.inspect
    raise(ArgumentError, message)
  end
end

Instance Method Details

#eachObject



88
89
90
91
92
93
94
# File 'lib/poppler/document.rb', line 88

def each
  return to_enum(__method__) unless block_given?

  n_pages.times do |i|
    yield get_page(i)
  end
end

#index_iterObject



106
107
108
# File 'lib/poppler/document.rb', line 106

def index_iter
  IndexIter.new(self)
end

#initialize_rawObject



23
# File 'lib/poppler/document.rb', line 23

alias_method :initialize_raw, :initialize

#save(uri) ⇒ Object



97
98
99
# File 'lib/poppler/document.rb', line 97

def save(uri)
  save_raw(ensure_uri(uri))
end

#save_a_copy(uri) ⇒ Object



102
103
104
# File 'lib/poppler/document.rb', line 102

def save_a_copy(uri)
  save_a_copy_raw(ensure_uri(uri))
end

#save_a_copy_rawObject



101
# File 'lib/poppler/document.rb', line 101

alias_method :save_a_copy_raw, :save_a_copy

#save_rawObject



96
# File 'lib/poppler/document.rb', line 96

alias_method :save_raw, :save