combine_pdf 0.2.5 → 0.2.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +273 -27
- data/LICENSE.txt +2 -1
- data/README.md +69 -4
- data/lib/combine_pdf/api.rb +156 -153
- data/lib/combine_pdf/basic_writer.rb +41 -53
- data/lib/combine_pdf/decrypt.rb +238 -228
- data/lib/combine_pdf/exceptions.rb +4 -0
- data/lib/combine_pdf/filter.rb +79 -85
- data/lib/combine_pdf/fonts.rb +451 -462
- data/lib/combine_pdf/page_methods.rb +891 -946
- data/lib/combine_pdf/parser.rb +663 -531
- data/lib/combine_pdf/pdf_protected.rb +341 -126
- data/lib/combine_pdf/pdf_public.rb +492 -454
- data/lib/combine_pdf/renderer.rb +146 -141
- data/lib/combine_pdf/version.rb +1 -2
- data/lib/combine_pdf.rb +14 -18
- data/test/automated +132 -0
- data/test/console +4 -4
- data/test/named_dest +84 -0
- metadata +8 -5
- data/lib/combine_pdf/operations.rb +0 -416
data/lib/combine_pdf/filter.rb
CHANGED
@@ -5,98 +5,92 @@
|
|
5
5
|
## is subject to the same license.
|
6
6
|
########################################################
|
7
7
|
|
8
|
-
|
9
|
-
|
10
8
|
module CombinePDF
|
11
|
-
|
12
|
-
|
13
|
-
protected
|
9
|
+
#:nodoc: all
|
14
10
|
|
15
|
-
|
11
|
+
protected
|
16
12
|
|
17
|
-
|
18
|
-
module PDFFilter
|
19
|
-
module_function
|
13
|
+
# @!visibility private
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
# <b>isn't supported yet!</b>
|
26
|
-
#
|
27
|
-
# object:: object to compress.
|
28
|
-
# filter:: filter to use.
|
29
|
-
def deflate_object object = nil, filter = :none
|
30
|
-
false
|
31
|
-
end
|
15
|
+
# This is an internal class. you don't need it.
|
16
|
+
module PDFFilter
|
17
|
+
module_function
|
32
18
|
|
33
|
-
|
34
|
-
#
|
35
|
-
# object:: object to decompress.
|
36
|
-
def inflate_object object = nil
|
37
|
-
return false unless object.is_a?(Hash)
|
38
|
-
filter_array = object[:Filter]
|
39
|
-
if filter_array.is_a?(Hash) && filter_array[:is_reference_only]
|
40
|
-
filter_array = filter_array[:referenced_object]
|
41
|
-
end
|
42
|
-
if filter_array.is_a?(Symbol)
|
43
|
-
filter_array = [filter_array]
|
44
|
-
end
|
45
|
-
filter_array = [] if filter_array.nil?
|
46
|
-
params_array = object[:DecodeParms]
|
47
|
-
if params_array.is_a?(Hash) && params_array[:is_reference_only]
|
48
|
-
params_array = params_array[:referenced_object]
|
49
|
-
end
|
50
|
-
unless params_array.is_a?(Array)
|
51
|
-
params_array = [params_array]
|
52
|
-
end
|
53
|
-
while filter_array[0]
|
54
|
-
case filter_array[0]
|
55
|
-
when :FlateDecode
|
56
|
-
raise_unsupported_error params_array[0] unless params_array[0].nil?
|
57
|
-
if params_array[0] && params_array[0][:Predictor].to_i > 1
|
58
|
-
bits = params_array[0][:BitsPerComponent] || 8
|
59
|
-
predictor = params_array[0][:Predictor].to_i
|
60
|
-
columns = params_array[0][:Columns] || 1
|
61
|
-
if (2..9).include? params_array[0][:Predictor].to_i
|
62
|
-
####
|
63
|
-
# prepare TIFF group
|
64
|
-
elsif (10..15).include? params_array[0][:Predictor].to_i == 2
|
65
|
-
####
|
66
|
-
# prepare PNG group
|
67
|
-
end
|
68
|
-
else
|
69
|
-
inflator = Zlib::Inflate.new
|
19
|
+
# @!visibility private
|
70
20
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
true
|
81
|
-
else
|
82
|
-
return false
|
83
|
-
end
|
84
|
-
params_array.shift
|
85
|
-
filter_array.shift
|
86
|
-
end
|
87
|
-
object.delete(:Filter)
|
88
|
-
true
|
89
|
-
end
|
90
|
-
|
91
|
-
protected
|
21
|
+
# deflate / compress an object.
|
22
|
+
#
|
23
|
+
# <b>isn't supported yet!</b>
|
24
|
+
#
|
25
|
+
# object:: object to compress.
|
26
|
+
# filter:: filter to use.
|
27
|
+
def deflate_object(_object = nil, _filter = :none)
|
28
|
+
false
|
29
|
+
end
|
92
30
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
31
|
+
# inflate / decompress an object
|
32
|
+
#
|
33
|
+
# object:: object to decompress.
|
34
|
+
def inflate_object(object = nil)
|
35
|
+
return false unless object.is_a?(Hash)
|
36
|
+
filter_array = object[:Filter]
|
37
|
+
if filter_array.is_a?(Hash) && filter_array[:is_reference_only]
|
38
|
+
filter_array = filter_array[:referenced_object]
|
39
|
+
end
|
40
|
+
filter_array = [filter_array] if filter_array.is_a?(Symbol)
|
41
|
+
filter_array = [] if filter_array.nil?
|
42
|
+
params_array = object[:DecodeParms]
|
43
|
+
if params_array.is_a?(Hash) && params_array[:is_reference_only]
|
44
|
+
params_array = params_array[:referenced_object]
|
45
|
+
end
|
46
|
+
params_array = [params_array] unless params_array.is_a?(Array)
|
47
|
+
object[:Filter] = filter_array
|
48
|
+
object[:DecodeParms] = params_array
|
49
|
+
while filter_array[0]
|
50
|
+
case filter_array[0]
|
51
|
+
when :FlateDecode
|
52
|
+
raise_unsupported_error params_array[0] unless params_array[0].nil?
|
53
|
+
if params_array[0] && params_array[0][:Predictor].to_i > 1
|
54
|
+
bits = params_array[0][:BitsPerComponent] || 8
|
55
|
+
predictor = params_array[0][:Predictor].to_i
|
56
|
+
columns = params_array[0][:Columns] || 1
|
57
|
+
if (2..9).cover? params_array[0][:Predictor].to_i
|
58
|
+
####
|
59
|
+
# prepare TIFF group
|
60
|
+
raise_unsupported_error params_array[0]
|
61
|
+
elsif (10..15).cover? params_array[0][:Predictor].to_i == 2
|
62
|
+
####
|
63
|
+
# prepare PNG group
|
64
|
+
raise_unsupported_error params_array[0]
|
65
|
+
end
|
66
|
+
else
|
67
|
+
inflator = Zlib::Inflate.new
|
100
68
|
|
69
|
+
object[:raw_stream_content] = inflator.inflate object[:raw_stream_content]
|
70
|
+
begin
|
71
|
+
inflator.finish
|
72
|
+
rescue
|
73
|
+
end
|
74
|
+
inflator.close
|
75
|
+
object[:Length] = object[:raw_stream_content].bytesize
|
76
|
+
end
|
77
|
+
when nil
|
78
|
+
true
|
79
|
+
else
|
80
|
+
return false
|
81
|
+
end
|
82
|
+
params_array.shift
|
83
|
+
filter_array.shift
|
84
|
+
end
|
85
|
+
object.delete :Filter
|
86
|
+
object.delete :DecodeParms
|
87
|
+
true
|
88
|
+
end
|
101
89
|
|
90
|
+
protected
|
102
91
|
|
92
|
+
def raise_unsupported_error(object = {})
|
93
|
+
raise "Filter #{object} unsupported. couldn't deflate object"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|