Class: Poppler::Document
- Inherits:
-
Object
- Object
- Poppler::Document
- Includes:
- Enumerable
- Defined in:
- lib/poppler/document.rb
Instance Method Summary collapse
- #each ⇒ Object
- #index_iter ⇒ Object
-
#initialize(*args) ⇒ Document
constructor
A new instance of Document.
- #initialize_raw ⇒ Object
- #save(uri) ⇒ Object
- #save_a_copy(uri) ⇒ Object
- #save_a_copy_raw ⇒ Object
- #save_raw ⇒ Object
Constructor Details
#initialize(*args) ⇒ Document
Returns a new instance of Document.
22 23 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 |
# File 'lib/poppler/document.rb', line 22 def initialize(*args) if args.size == 1 and args[0].is_a?(Hash) = args[0] else uri_or_data, password = args if pdf_data?(uri_or_data) = { :data => uri_or_data, :password => password } else = { :uri => ensure_uri(uri_or_data), :password => password } end end data = [:data] uri = [:uri] path = [:path] stream = [:stream] length = [:length] file = [:file] password = [:password] if data # Workaround: poppler_document_new_from_data()'s .gir # accepts PDF data as UTF-8 string. PDF data is not UTF-8 # string. So UTF-8 validation is failed. # # TODO: Enable the following: # initialize_new_from_data(data, password) @bytes = GLib::Bytes.new(data) @stream = Gio::MemoryInputStream.new(@bytes) initialize_new_from_stream(@stream, data.bytesize, password) 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: #{.inspect}") end initialize_new_from_stream(stream, length, password) elsif file if file.is_a?(String) initialize(path: file, password: password) else initialize_new_from_gfile(file, password) end else = "must specify one of :data, :uri, :path, :stream or :file: " + .inspect raise(ArgumentError, ) end end |
Instance Method Details
#each ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/poppler/document.rb', line 86 def each return to_enum(__method__) unless block_given? n_pages.times do |i| yield get_page(i) end end |
#index_iter ⇒ Object
104 105 106 |
# File 'lib/poppler/document.rb', line 104 def index_iter IndexIter.new(self) end |
#initialize_raw ⇒ Object
21 |
# File 'lib/poppler/document.rb', line 21 alias_method :initialize_raw, :initialize |
#save(uri) ⇒ Object
95 96 97 |
# File 'lib/poppler/document.rb', line 95 def save(uri) save_raw(ensure_uri(uri)) end |
#save_a_copy(uri) ⇒ Object
100 101 102 |
# File 'lib/poppler/document.rb', line 100 def save_a_copy(uri) save_a_copy_raw(ensure_uri(uri)) end |
#save_a_copy_raw ⇒ Object
99 |
# File 'lib/poppler/document.rb', line 99 alias_method :save_a_copy_raw, :save_a_copy |
#save_raw ⇒ Object
94 |
# File 'lib/poppler/document.rb', line 94 alias_method :save_raw, :save |