poppler 3.1.9 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +8 -3
- data/lib/poppler/document.rb +55 -36
- data/test/test-document.rb +24 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c42916c4826ecaa28b3dc30abae1a6ce2dda547
|
4
|
+
data.tar.gz: cf4048091a50a73f4b2d9a455159d300348720f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4d0817f1d8365bb78eae942d000971edad42dc99dc8561a559aeeb1ee9db48027a73fcac087ec3a169a8f82218614cf0b49f0df9f21ec08e7810865d587908
|
7
|
+
data.tar.gz: f4151e74cb7348e4a9dbf3ef46b5d7989d69b84fb130c9f2603558d62df8a0d72db92314eb3162573a2dc2d6170600f9f2a4ef40561131ceafbe4c5c0605f542
|
data/Rakefile
CHANGED
@@ -22,16 +22,21 @@ require 'gnome2-raketask'
|
|
22
22
|
package_task = GNOME2::Rake::PackageTask.new do |package|
|
23
23
|
package.summary = "Ruby/Poppler is a Ruby binding of poppler-glib."
|
24
24
|
package.description = "Ruby/Poppler is a Ruby binding of poppler-glib."
|
25
|
-
package.dependency.gem.runtime = [
|
25
|
+
package.dependency.gem.runtime = [
|
26
|
+
"cairo-gobject",
|
27
|
+
"gio2",
|
28
|
+
]
|
26
29
|
package.windows.packages = []
|
27
30
|
package.windows.dependencies = []
|
28
31
|
package.windows.build_dependencies = [
|
29
32
|
"glib2",
|
30
33
|
"gobject-introspection",
|
31
|
-
"
|
34
|
+
"gio2",
|
35
|
+
"cairo-gobject",
|
32
36
|
]
|
33
37
|
package.windows.gobject_introspection_dependencies = [
|
34
|
-
"
|
38
|
+
"gio2",
|
39
|
+
"cairo-gobject",
|
35
40
|
]
|
36
41
|
package.external_packages = [
|
37
42
|
{
|
data/lib/poppler/document.rb
CHANGED
@@ -22,48 +22,63 @@ module Poppler
|
|
22
22
|
def initialize(*args)
|
23
23
|
if args.size == 1 and args[0].is_a?(Hash)
|
24
24
|
options = args[0]
|
25
|
-
data = options[:data]
|
26
|
-
uri = options[:uri]
|
27
|
-
path = options[:path]
|
28
|
-
stream = options[:stream]
|
29
|
-
length = options[:length]
|
30
|
-
file = options[:file]
|
31
|
-
password = options[:password]
|
32
|
-
|
33
|
-
if data
|
34
|
-
initialize_new_from_data(data, password)
|
35
|
-
elsif uri
|
36
|
-
initialize_new_from_file(uri, password)
|
37
|
-
elsif path
|
38
|
-
uri = ensure_uri(path)
|
39
|
-
initialize_new_from_file(uri, password)
|
40
|
-
elsif stream
|
41
|
-
if length.nil?
|
42
|
-
raise(ArgumentError,
|
43
|
-
"must specify :length for :stream: #{options.inspect}")
|
44
|
-
end
|
45
|
-
initialize_new_from_stream(stream, length, password)
|
46
|
-
elsif file
|
47
|
-
if file.is_a?(String)
|
48
|
-
initialize(path: file, password: password)
|
49
|
-
else
|
50
|
-
initialize_new_from_gfile(file, password)
|
51
|
-
end
|
52
|
-
else
|
53
|
-
message =
|
54
|
-
"must specify one of :data, :uri, :path, :stream or :file: " +
|
55
|
-
options.inspect
|
56
|
-
raise(ArgumentError, message)
|
57
|
-
end
|
58
25
|
else
|
59
26
|
uri_or_data, password = args
|
60
27
|
if pdf_data?(uri_or_data)
|
61
|
-
|
28
|
+
options = {
|
29
|
+
:data => uri_or_data,
|
30
|
+
:password => password
|
31
|
+
}
|
62
32
|
else
|
63
|
-
|
64
|
-
|
33
|
+
options = {
|
34
|
+
:uri => ensure_uri(uri_or_data),
|
35
|
+
:password => password
|
36
|
+
}
|
65
37
|
end
|
66
38
|
end
|
39
|
+
|
40
|
+
data = options[:data]
|
41
|
+
uri = options[:uri]
|
42
|
+
path = options[:path]
|
43
|
+
stream = options[:stream]
|
44
|
+
length = options[:length]
|
45
|
+
file = options[:file]
|
46
|
+
password = options[:password]
|
47
|
+
|
48
|
+
if data
|
49
|
+
# Workaround: poppler_document_new_from_data()'s .gir
|
50
|
+
# accepts PDF data as UTF-8 string. PDF data is not UTF-8
|
51
|
+
# string. So UTF-8 validation is failed.
|
52
|
+
#
|
53
|
+
# TODO: Enable the following:
|
54
|
+
# initialize_new_from_data(data, password)
|
55
|
+
|
56
|
+
@bytes = GLib::Bytes.new(data)
|
57
|
+
@stream = Gio::MemoryInputStream.new(@bytes)
|
58
|
+
initialize_new_from_stream(@stream, data.bytesize, password)
|
59
|
+
elsif uri
|
60
|
+
initialize_new_from_file(uri, password)
|
61
|
+
elsif path
|
62
|
+
uri = ensure_uri(path)
|
63
|
+
initialize_new_from_file(uri, password)
|
64
|
+
elsif stream
|
65
|
+
if length.nil?
|
66
|
+
raise(ArgumentError,
|
67
|
+
"must specify :length for :stream: #{options.inspect}")
|
68
|
+
end
|
69
|
+
initialize_new_from_stream(stream, length, password)
|
70
|
+
elsif file
|
71
|
+
if file.is_a?(String)
|
72
|
+
initialize(path: file, password: password)
|
73
|
+
else
|
74
|
+
initialize_new_from_gfile(file, password)
|
75
|
+
end
|
76
|
+
else
|
77
|
+
message =
|
78
|
+
"must specify one of :data, :uri, :path, :stream or :file: " +
|
79
|
+
options.inspect
|
80
|
+
raise(ArgumentError, message)
|
81
|
+
end
|
67
82
|
end
|
68
83
|
|
69
84
|
alias_method :[], :get_page
|
@@ -90,6 +105,10 @@ module Poppler
|
|
90
105
|
IndexIter.new(self)
|
91
106
|
end
|
92
107
|
|
108
|
+
alias_method :size, :n_pages
|
109
|
+
|
110
|
+
alias_method :pages, :to_a
|
111
|
+
|
93
112
|
private
|
94
113
|
def pdf_data?(data)
|
95
114
|
data.start_with?("%PDF-1.")
|
data/test/test-document.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
class TestDocument < Test::Unit::TestCase
|
2
|
+
sub_test_case("#initialize") do
|
3
|
+
def test_data
|
4
|
+
pdf = StringIO.new
|
5
|
+
surface = Cairo::PDFSurface.new(pdf, 100, 100)
|
6
|
+
context = Cairo::Context.new(surface)
|
7
|
+
context.show_text("Hello")
|
8
|
+
surface.finish
|
9
|
+
|
10
|
+
document = Poppler::Document.new(:data => pdf.string)
|
11
|
+
assert_equal("Hello", document[0].text)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
2
15
|
def test_save
|
3
16
|
saved_pdf = File.join(tmp_dir, "saved.pdf")
|
4
17
|
FileUtils.rm_f(saved_pdf)
|
@@ -45,6 +58,17 @@ class TestDocument < Test::Unit::TestCase
|
|
45
58
|
document.collect(&:text))
|
46
59
|
end
|
47
60
|
|
61
|
+
def test_size
|
62
|
+
document = Poppler::Document.new(multiple_pages_pdf)
|
63
|
+
assert_equal(2, document.size)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_pages
|
67
|
+
document = Poppler::Document.new(multiple_pages_pdf)
|
68
|
+
assert_equal(["The first page", "The second page"],
|
69
|
+
document.pages.collect(&:text))
|
70
|
+
end
|
71
|
+
|
48
72
|
private
|
49
73
|
def find_first_text_field(document)
|
50
74
|
document.each do |page|
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poppler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Ruby-GNOME2 Project Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: cairo
|
14
|
+
name: cairo-gobject
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: gio2
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.2.0
|
41
41
|
description: Ruby/Poppler is a Ruby binding of poppler-glib.
|
42
42
|
email: ruby-gnome2-devel-en@lists.sourceforge.net
|
43
43
|
executables: []
|