combine_pdf 0.2.14 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -4
- data/lib/combine_pdf/page_methods.rb +27 -19
- data/lib/combine_pdf/renderer.rb +8 -2
- data/lib/combine_pdf/version.rb +1 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3048c37a61edc6d2146a875b7858a67c45cdfee
|
4
|
+
data.tar.gz: 1c34bcc2d900f23c56bd67ea9e83ed7cc5d8ac85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cccfd304beb820569452b222725da35df09711ff9c63c96a5b8a73f306f9756d83f86536bb0214789ede6fd380dd8f77615eadec36de7f909b268af0f030b65
|
7
|
+
data.tar.gz: cb6331c3bc3cb57a51034018ee07549fb67d69f05692121a92b48584b6d70c9a581678b804b318d8e87dd2a6f48c9d4eb06ad071dff61213244d941fede3e9d8
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
***
|
4
4
|
|
5
|
+
Change log v.0.2.15
|
6
|
+
|
7
|
+
**Fix**: Fix for issue #22 where specific PDF files with nested references could cause page stamping to fail, raising an exception. Credit to @tomascharad for finding the issue.
|
8
|
+
|
9
|
+
***
|
10
|
+
|
5
11
|
Change log v.0.2.14
|
6
12
|
|
7
|
-
**Fix**: Fix for issue #39, where certain comments could have caused the object after the comments to be ignored, resulting in parsing errors.
|
13
|
+
**Fix**: Fix for issue #39, where certain comments could have caused the object after the comments to be ignored, resulting in parsing errors. Credit to @lgn21st for identifying the issue.
|
8
14
|
|
9
15
|
***
|
10
16
|
|
@@ -50,7 +56,7 @@ Change log v.0.2.8
|
|
50
56
|
|
51
57
|
Now there is no longer any need for the guesswork. The process is automated for you.
|
52
58
|
|
53
|
-
The moment CombinePDF recognizes a resource name conflice between two pages (such as both pages using one font name to reference two different fonts), CombinePDF will intrusively rename the incoming page's resources.
|
59
|
+
The moment CombinePDF recognizes a resource name conflice between two pages (such as both pages using one font name to reference two different fonts), CombinePDF will intrusively rename the incoming page's resources.
|
54
60
|
|
55
61
|
It is true that the intrusive resource renaming is somewhat risky and might require the inflation of some comperssed page data (resulting in bigger file sizes), but this is the only way to attempt and prevent PDF data curruption.
|
56
62
|
|
@@ -170,7 +176,7 @@ Change log v.0.1.19
|
|
170
176
|
|
171
177
|
Change log v.0.1.18
|
172
178
|
|
173
|
-
**fix**: Thank to Stefan, who reported issue #15 , we discovered that in some cases PDF files presented the wrong PDF standard version, causing an error while attempting to parse their data. The issue has been fixed by allowing the parser to search for PDF Object Streams even when the PDF file claims a PDF version below 1.5.
|
179
|
+
**fix**: Thank to Stefan, who reported issue #15 , we discovered that in some cases PDF files presented the wrong PDF standard version, causing an error while attempting to parse their data. The issue has been fixed by allowing the parser to search for PDF Object Streams even when the PDF file claims a PDF version below 1.5.
|
174
180
|
|
175
181
|
***
|
176
182
|
|
@@ -259,4 +265,4 @@ Change log v.0.1.6
|
|
259
265
|
|
260
266
|
**known issues**: encrypted PDF files can sometimes silently fail (producing empty pages) - this is because on an attempted decrypt. more work should be done to support encrypted PDF files. please feel fee to help.
|
261
267
|
|
262
|
-
I use this version on production, where I have control over the PDF files I use. It is beter then system calls to pdftk (which can cause all threads in ruby to hold, effectively causing my web app to hang).
|
268
|
+
I use this version on production, where I have control over the PDF files I use. It is beter then system calls to pdftk (which can cause all threads in ruby to hold, effectively causing my web app to hang).
|
@@ -52,7 +52,7 @@ module CombinePDF
|
|
52
52
|
inject_page obj, false
|
53
53
|
end
|
54
54
|
def inject_page obj, top = true
|
55
|
-
|
55
|
+
|
56
56
|
raise TypeError, "couldn't inject data, expecting a PDF page (Hash type)" unless obj.is_a?(Page_Methods)
|
57
57
|
|
58
58
|
obj = obj.copy( should_secure?(obj) ) #obj.copy(secure_injection)
|
@@ -115,7 +115,7 @@ module CombinePDF
|
|
115
115
|
|
116
116
|
# get page size
|
117
117
|
def page_size
|
118
|
-
cropbox || mediabox
|
118
|
+
cropbox || mediabox
|
119
119
|
end
|
120
120
|
|
121
121
|
# accessor (getter) for the :Resources element of the page
|
@@ -223,7 +223,7 @@ module CombinePDF
|
|
223
223
|
radius = options[:box_radius]
|
224
224
|
half_radius = (radius.to_f / 2).round 4
|
225
225
|
## set starting point
|
226
|
-
box_stream << "#{options[:x] + radius} #{options[:y]} m\n"
|
226
|
+
box_stream << "#{options[:x] + radius} #{options[:y]} m\n"
|
227
227
|
## buttom and right corner - first line and first corner
|
228
228
|
box_stream << "#{options[:x] + options[:width] - radius} #{options[:y]} l\n" #buttom
|
229
229
|
if options[:box_radius] != 0 # make first corner, if not straight.
|
@@ -326,7 +326,7 @@ module CombinePDF
|
|
326
326
|
# format text object(s)
|
327
327
|
# text_stream << "#{options[:font_color].join(' ')} rg\n" # sets the color state
|
328
328
|
encode_text(text, fonts).each do |encoded|
|
329
|
-
text_stream << "BT\n" # the Begine Text marker
|
329
|
+
text_stream << "BT\n" # the Begine Text marker
|
330
330
|
text_stream << format_name_to_pdf(set_font encoded[0]) # Set font name
|
331
331
|
text_stream << " #{font_size.round 3} Tf\n" # set font size and add font operator
|
332
332
|
text_stream << "#{x.round 4} #{y.round 4} Td\n" # set location for text object
|
@@ -571,7 +571,7 @@ module CombinePDF
|
|
571
571
|
box_color = (options[:alternate_color] && ( (row_number.odd? && options[:headers]) || row_number.even? ) ) ? options[:alternate_color] : options[:main_color]
|
572
572
|
textbox text, {x: x, y: (top - (height*row_number)), width: column_widths[i], height: height, box_color: box_color, text_align: options[:row_align]}.merge(options)
|
573
573
|
x += column_widths[i]
|
574
|
-
end
|
574
|
+
end
|
575
575
|
row_number += 1
|
576
576
|
end
|
577
577
|
self
|
@@ -615,7 +615,12 @@ module CombinePDF
|
|
615
615
|
#initializes the content stream in case it was not initialized before
|
616
616
|
def init_contents
|
617
617
|
self[:Contents] = self[:Contents][:referenced_object][:indirect_without_dictionary] if self[:Contents].is_a?(Hash) && self[:Contents][:referenced_object] && self[:Contents][:referenced_object].is_a?(Hash) && self[:Contents][:referenced_object][:indirect_without_dictionary]
|
618
|
+
self[:Contents] = [self[:Contents]] unless self[:Contents].is_a?(Array)
|
618
619
|
self[:Contents].delete({ is_reference_only: true , referenced_object: {indirect_reference_id: 0, raw_stream_content: ''} })
|
620
|
+
# un-nest any referenced arrays
|
621
|
+
self[:Contents].map! {|s| actual_value(s).is_a?(Array) ? actual_value(s) : s}
|
622
|
+
self[:Contents].flatten!
|
623
|
+
self[:Contents].compact!
|
619
624
|
# wrap content streams
|
620
625
|
insert_content 'q', 0
|
621
626
|
insert_content 'Q'
|
@@ -642,8 +647,11 @@ module CombinePDF
|
|
642
647
|
|
643
648
|
def prep_content_array
|
644
649
|
return self if self[:Contents].is_a?(Array)
|
645
|
-
|
646
|
-
self[:Contents] = [ self[:Contents] ].
|
650
|
+
init_contents
|
651
|
+
# self[:Contents] = self[:Contents][:referenced_object] if self[:Contents].is_a?(Hash) && self[:Contents][:referenced_object] && self[:Contents][:referenced_object].is_a?(Array)
|
652
|
+
# self[:Contents] = self[:Contents][:indirect_without_dictionary] if self[:Contents].is_a?(Hash) && self[:Contents][:indirect_without_dictionary] && self[:Contents][:indirect_without_dictionary].is_a?(Array)
|
653
|
+
# self[:Contents] = [self[:Contents]] unless self[:Contents].is_a?(Array)
|
654
|
+
# self[:Contents].compact!
|
647
655
|
self
|
648
656
|
end
|
649
657
|
|
@@ -729,7 +737,7 @@ module CombinePDF
|
|
729
737
|
#add to array
|
730
738
|
if out.last.nil? || out.last[0] != fonts[i]
|
731
739
|
out.last[1] << ">" unless out.last.nil?
|
732
|
-
out << [fonts[i], "<" , 0, 0]
|
740
|
+
out << [fonts[i], "<" , 0, 0]
|
733
741
|
end
|
734
742
|
out.last[1] << ( fonts_array[i].cmap.nil? ? ( c.unpack("H*")[0] ) : (fonts_array[i].cmap[c]) )
|
735
743
|
if fonts_array[i].metrics[c]
|
@@ -791,7 +799,7 @@ module CombinePDF
|
|
791
799
|
# travel every dictionary to pick up names (keys), change them and add them to the dictionary
|
792
800
|
res = self.resources
|
793
801
|
res.each do |k,v|
|
794
|
-
if v.is_a?(Hash)
|
802
|
+
if actual_value(v).is_a?(Hash)
|
795
803
|
# if k == :XObject
|
796
804
|
# self[:Resources][k] = v.dup
|
797
805
|
# next
|
@@ -799,7 +807,7 @@ module CombinePDF
|
|
799
807
|
new_dictionary = {}
|
800
808
|
new_name = "Combine" + SecureRandom.hex(7) + "PDF"
|
801
809
|
i = 1
|
802
|
-
|
810
|
+
actual_value(v).each do |old_key, value|
|
803
811
|
new_key = (new_name + i.to_s).to_sym
|
804
812
|
names_dictionary[old_key] = new_key
|
805
813
|
new_dictionary[new_key] = value
|
@@ -814,10 +822,10 @@ module CombinePDF
|
|
814
822
|
# we will need to make sure we have access to the stream injected
|
815
823
|
# we will user PDFFilter.inflate_object
|
816
824
|
self[:Contents].each do |c|
|
817
|
-
stream =
|
825
|
+
stream = actual_value(c)
|
818
826
|
PDFFilter.inflate_object stream
|
819
827
|
names_dictionary.each do |old_key, new_key|
|
820
|
-
stream[:raw_stream_content].gsub! object_to_pdf(old_key), object_to_pdf(new_key) ##### PRAY(!) that the parsed datawill be correctly reproduced!
|
828
|
+
stream[:raw_stream_content].gsub! object_to_pdf(old_key), object_to_pdf(new_key) ##### PRAY(!) that the parsed datawill be correctly reproduced!
|
821
829
|
end
|
822
830
|
# # # the following code isn't needed now that we wrap both the existing and incoming content streams.
|
823
831
|
# # patch back to PDF defaults, for OCRed PDF files.
|
@@ -831,15 +839,15 @@ module CombinePDF
|
|
831
839
|
# travel every dictionary to pick up names (keys), change them and add them to the dictionary
|
832
840
|
res = self.resources
|
833
841
|
foreign_res = page.resources
|
834
|
-
res.each
|
842
|
+
res.each do |k,v|
|
843
|
+
if actual_value(v).is_a?(Hash) && actual_value(foreign_res[k]).is_a?(Hash)
|
844
|
+
v.keys.each do |name| return true if actual_value(foreign_res[k]) && actual_value(foreign_res[k])[name] && actual_value(foreign_res[k])[name] != actual_value(v[k])[name]
|
845
|
+
end # else # Do nothing, this is taken care of elseware
|
846
|
+
end
|
847
|
+
end
|
835
848
|
false
|
836
849
|
end
|
837
850
|
|
838
851
|
end
|
839
|
-
|
840
|
-
end
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
852
|
|
853
|
+
end
|
data/lib/combine_pdf/renderer.rb
CHANGED
@@ -53,7 +53,7 @@ module CombinePDF
|
|
53
53
|
("(" + ([].tap {|out| object.bytes.each {|byte| STRING_REPLACEMENT_HASH[ byte.chr ] ? (STRING_REPLACEMENT_HASH[ byte.chr ].bytes.each {|b| out << b}) : out << byte } }).pack('C*') + ")").force_encoding(Encoding::ASCII_8BIT)
|
54
54
|
else
|
55
55
|
# A hexadecimal string shall be written as a sequence of hexadecimal digits (0–9 and either A–F or a–f)
|
56
|
-
# encoded as ASCII characters and enclosed within angle brackets (using LESS-THAN SIGN (3Ch) and GREATER- THAN SIGN (3Eh)).
|
56
|
+
# encoded as ASCII characters and enclosed within angle brackets (using LESS-THAN SIGN (3Ch) and GREATER- THAN SIGN (3Eh)).
|
57
57
|
("<" + object.unpack('H*')[0] + ">").force_encoding(Encoding::ASCII_8BIT)
|
58
58
|
end
|
59
59
|
end
|
@@ -83,7 +83,7 @@ module CombinePDF
|
|
83
83
|
# An array shall be written as a sequence of objects enclosed in SQUARE BRACKETS (using LEFT SQUARE BRACKET (5Bh) and RIGHT SQUARE BRACKET (5Dh)).
|
84
84
|
# EXAMPLE [549 3.14 false (Ralph) /SomeName]
|
85
85
|
("[" + (object.collect {|item| object_to_pdf(item)}).join(' ') + "]").force_encoding(Encoding::ASCII_8BIT)
|
86
|
-
|
86
|
+
|
87
87
|
end
|
88
88
|
|
89
89
|
def format_hash_to_pdf(object)
|
@@ -135,6 +135,12 @@ module CombinePDF
|
|
135
135
|
obj.is_a?(Hash) ? (obj[:referenced_object] || obj) : obj
|
136
136
|
end
|
137
137
|
|
138
|
+
def actual_value obj
|
139
|
+
return obj unless obj.is_a?(Hash)
|
140
|
+
obj = obj[:referenced_object] || obj
|
141
|
+
obj[:indirect_without_dictionary] || obj
|
142
|
+
end
|
143
|
+
|
138
144
|
# Ruby normally assigns pointes.
|
139
145
|
# noramlly:
|
140
146
|
# a = [1,2,3] # => [1,2,3]
|
data/lib/combine_pdf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combine_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-rc4
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.5.1
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Combine, stamp and watermark PDF files in pure Ruby.
|