combine_pdf 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f66dc648f9871931fd703730cb5f876d41f17f95
4
- data.tar.gz: f0e29ec0a4fdc4950c5f85f48ec5ea7eb556c03d
3
+ metadata.gz: 1bfb2a58c87c43e094eda71bc971b99aac3675ac
4
+ data.tar.gz: 0f6bcfd43bab6cfefb7d27683fe034df25af740b
5
5
  SHA512:
6
- metadata.gz: fefebcb9e77a306f4099e91f05fc60efa2596b33afc2ff484562d82cda06494d86e11349c00e6724ad5978b4795cf999236fa273d933df25a93e9975f91e9e65
7
- data.tar.gz: 8f2e46ba6d0b3f136d80a38b95d85b6271b433216fa59faea82bf668835a356b65399d87a35fda7e095e3d03d210768fb2b659df3546ddafb4df734fbc8517a7
6
+ metadata.gz: f1fe8e6cc9a5c0f2643c6500b4560c1818bf02f894c9d995443f38416f4839e0fdb551a2c96ee298bbedb3d2968a69230a9fd330efd1e7bbf3349a897c3b0e79
7
+ data.tar.gz: 155bacd58c22e799dc3db655fc89e4fe03d536287a71883edb2ce8ce7deb051d538773c34e51e4d1cd8a553feaf6c934675510bd37529cfd81a16a614faf0dd5
@@ -2,6 +2,16 @@
2
2
 
3
3
  ***
4
4
 
5
+ Change log v.0.2.13
6
+
7
+ **Fix** fixed issue # 37 reported by @sega (thank you for reporting!), regarding the insability to stamp one PDF page over another when one PDF page used a resource directory propegated with data and another page used a resource directory propegated with references. This was now resolved by checking for references before merging the data.
8
+
9
+ **Compatability**: fixed an issue where PrimoPDF would ommit the required EOL marker before the `endstream`. This would cause malformed PDF files to be written and it is now resolved by allowing the required EOL to be optional.
10
+
11
+ **Minor**: a minor improvement on the compatability fix related to salvaging PDF data that was misplaced within a PDF comment. This improvement relates to the possibility that there might not be an EOL marker after the `obj` keyword (PaperPort does use an EOL after the `obj` keyword, so this isn't critical).
12
+
13
+ ***
14
+
5
15
  Change log v.0.2.12
6
16
 
7
17
  **Compatability**: fixed issue #36 reported by @vitstradal (thank you for reporting!) regarding PDF files composed by PaperPort. PaperPort (at least version 12) has an issue where PDF data will be placed within a PDF comment. PDF comments start with a "%" sign and end with an EOL marker ("\r" or "\n"). PaperPort ommitted the EOL marker, placing critical data within the comment. A work-around was found by parsing the comment's data and attempting to salvage the misplaced data. This workaround assumes that comments would not contain PDF parsable data at the very end of the comment's line... which is an unsafe assumption. hence, **please let me know if you find _any_ PDF files that worked before the workaround was introduced**.
@@ -50,6 +50,8 @@ module CombinePDF
50
50
  unless params_array.is_a?(Array)
51
51
  params_array = [params_array]
52
52
  end
53
+ object[:Filter] = filter_array
54
+ object[:DecodeParms] = params_array
53
55
  while filter_array[0]
54
56
  case filter_array[0]
55
57
  when :FlateDecode
@@ -61,9 +63,11 @@ module CombinePDF
61
63
  if (2..9).include? params_array[0][:Predictor].to_i
62
64
  ####
63
65
  # prepare TIFF group
66
+ raise_unsupported_error params_array[0]
64
67
  elsif (10..15).include? params_array[0][:Predictor].to_i == 2
65
68
  ####
66
69
  # prepare PNG group
70
+ raise_unsupported_error params_array[0]
67
71
  end
68
72
  else
69
73
  inflator = Zlib::Inflate.new
@@ -84,7 +88,8 @@ module CombinePDF
84
88
  params_array.shift
85
89
  filter_array.shift
86
90
  end
87
- object.delete(:Filter)
91
+ object.delete :Filter
92
+ object.delete :DecodeParms
88
93
  true
89
94
  end
90
95
 
@@ -67,8 +67,9 @@ module CombinePDF
67
67
  if res[key].nil?
68
68
  res[key] = new_val
69
69
  elsif res[key].is_a?(Hash) && new_val.is_a?(Hash)
70
- new_val.update resources[key] # make sure the old values are respected
71
- res[key].update new_val # transfer old and new values to the injected page
70
+ new_val = new_val[:referenced_object] || new_val
71
+ new_val.update (res[key][:referenced_object] || res[key]) # make sure the old values are respected
72
+ (res[key][:referenced_object] || res[key]).update new_val # transfer old and new values to the injected page
72
73
  end #Do nothing if array - ot is the PROC array, which is an issue
73
74
  end
74
75
  end
@@ -670,19 +671,20 @@ module CombinePDF
670
671
  def set_font(font = :Helvetica)
671
672
  # if the font exists, return it's name
672
673
  resources[:Font] ||= {}
673
- resources[:Font].each do |k,v|
674
+ fonts_res = resources[:Font][:referenced_object] || resources[:Font]
675
+ fonts_res.each do |k,v|
674
676
  if v.is_a?(Fonts::Font) && v.name && v.name == font
675
677
  return k
676
678
  end
677
679
  end
678
680
  # set a secure name for the font
679
- name = (base_font_name + (resources[:Font].length + 1).to_s).to_sym
681
+ name = (base_font_name + (fonts_res.length + 1).to_s).to_sym
680
682
  # get font object
681
683
  font_object = Fonts.get_font(font)
682
684
  # return false if the font wan't found in the library.
683
685
  return false unless font_object
684
686
  # add object to reasource
685
- resources[:Font][name] = font_object
687
+ fonts_res[name] = font_object
686
688
  #return name
687
689
  name
688
690
  end
@@ -691,7 +693,8 @@ module CombinePDF
691
693
  def graphic_state(graphic_state_dictionary = {})
692
694
  # if the graphic state exists, return it's name
693
695
  resources[:ExtGState] ||= {}
694
- resources[:ExtGState].each do |k,v|
696
+ gs_res = resources[:ExtGState][:referenced_object] || resources[:ExtGState]
697
+ gs_res.each do |k,v|
695
698
  if v.is_a?(Hash) && v == graphic_state_dictionary
696
699
  return k
697
700
  end
@@ -701,7 +704,7 @@ module CombinePDF
701
704
  # set a secure name for the graphic state
702
705
  name = (SecureRandom.hex(9)).to_sym
703
706
  # add object to reasource
704
- resources[:ExtGState][name] = graphic_state_dictionary
707
+ gs_res[name] = graphic_state_dictionary
705
708
  #return name
706
709
  name
707
710
  end
@@ -796,7 +799,7 @@ module CombinePDF
796
799
  new_dictionary = {}
797
800
  new_name = "Combine" + SecureRandom.hex(7) + "PDF"
798
801
  i = 1
799
- v.each do |old_key, value|
802
+ actual_object(v).each do |old_key, value|
800
803
  new_key = (new_name + i.to_s).to_sym
801
804
  names_dictionary[old_key] = new_key
802
805
  new_dictionary[new_key] = value
@@ -828,7 +831,7 @@ module CombinePDF
828
831
  # travel every dictionary to pick up names (keys), change them and add them to the dictionary
829
832
  res = self.resources
830
833
  foreign_res = page.resources
831
- res.each {|k,v| v.keys.each {|name| return true if foreign_res[k] && foreign_res[k][name] && foreign_res[k][name] != v[name]} if v.is_a?(Hash) }
834
+ res.each {|k,v| v.keys.each {|name| return true if foreign_res[k] && (foreign_res[k][:referenced_object] || foreign_res[k])[name] && (foreign_res[k][:referenced_object] || foreign_res[k])[name] != (v[:referenced_object] || v)[name]} if v.is_a?(Hash) }
832
835
  false
833
836
  end
834
837
 
@@ -203,10 +203,10 @@ module CombinePDF
203
203
  # need to remove end of stream
204
204
  if out.last.is_a? Hash
205
205
  # out.last[:raw_stream_content] = str[0...-10] #cuts only one EON char (\n or \r)
206
- out.last[:raw_stream_content] = unify_string str.sub(/[\n\r]?[\n\r]endstream\z/, "").force_encoding(Encoding::ASCII_8BIT)
206
+ out.last[:raw_stream_content] = unify_string str.sub(/(\r\n|\n|\r)?endstream\z/, "").force_encoding(Encoding::ASCII_8BIT)
207
207
  else
208
208
  warn "Stream not attached to dictionary!"
209
- out << str.sub(/[\n\r]?[\n\r]endstream\z/, "").force_encoding(Encoding::ASCII_8BIT)
209
+ out << str.sub(/(\r\n|\n|\r)?endstream\z/, "").force_encoding(Encoding::ASCII_8BIT)
210
210
  end
211
211
  ##########################################
212
212
  ## parse an Object after finished
@@ -316,7 +316,7 @@ module CombinePDF
316
316
  #is a comment, skip until new line
317
317
  loop do
318
318
  break unless @scanner.scan(/[^\d\r\n]+/)
319
- break if @scanner.check(/([\d]+ [\d]+ obj)?[\n\r]+/)
319
+ break if @scanner.check(/([\d]+[\s]+[\d]+[\s]+obj[\n\r\s]+\<\<)|([\n\r]+)/)
320
320
  break if @scanner.eos?
321
321
  @scanner.pos += 1
322
322
  end
@@ -112,6 +112,8 @@ module CombinePDF
112
112
  return out.join().force_encoding(Encoding::ASCII_8BIT)
113
113
  end
114
114
  end
115
+ # remove extra page references.
116
+ object[:Contents].delete({ is_reference_only: true , referenced_object: {indirect_reference_id: 0, raw_stream_content: ''} }) if object[:Type] == :Page
115
117
  # correct stream length, if the object is a stream.
116
118
  object[:Length] = object[:raw_stream_content].bytesize if object[:raw_stream_content]
117
119
 
@@ -122,6 +124,7 @@ module CombinePDF
122
124
  object.each do |key, value|
123
125
  out << "#{object_to_pdf key} #{object_to_pdf value}\n".force_encoding(Encoding::ASCII_8BIT) unless PDF::PRIVATE_HASH_KEYS.include? key
124
126
  end
127
+ object.delete :Length
125
128
  out << ">>".force_encoding(Encoding::ASCII_8BIT)
126
129
  out << "\nstream\n#{object[:raw_stream_content]}\nendstream".force_encoding(Encoding::ASCII_8BIT) if object[:raw_stream_content]
127
130
  out << "\nendobj\n" if object[:indirect_reference_id]
@@ -1,4 +1,4 @@
1
1
  module CombinePDF
2
- VERSION = "0.2.12"
2
+ VERSION = "0.2.13"
3
3
  end
4
4
 
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.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-19 00:00:00.000000000 Z
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4