combine_pdf 1.0.1 → 1.0.2

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: dab047c1632f06fe95ade20bd50476f66260c877
4
- data.tar.gz: 32fb4875dfd46b48f50e262a4f0a00d8522861a2
3
+ metadata.gz: bb9d21d934a1001210f09268503f3ebc0282aedf
4
+ data.tar.gz: fc180c13f7789f87e32e06f0307093a485dfe560
5
5
  SHA512:
6
- metadata.gz: 955acdc11d89d5e1f5d5033bfaa8438633f4068bc09ddadb3e77852e0c5cc6544ee4b38f4c67f6a3b24fdfec334c4e1ce4fb3cc6e257b11bd9584832138b7c37
7
- data.tar.gz: f70ac4f27e87cf913b52be0dc60eb90e32002bedd1bb30cb2c4ee9452866d66e7d30828a516f20ab291effd2dfe0404b0fad9b649315c66f455b62effd9aee95
6
+ metadata.gz: 7b9d84a43b214ab50f9c9aca37ddb4d1532f2c72d5ec8b441119f0bfb33e2b295267def67acc6787254cd0760f8e44ba358054cd311eb6619a9d5edc125095b6
7
+ data.tar.gz: 7bed5345b025c0633c2cad6bd7b861d34e962f17f002d840f99a9159ec7d5d3529ebfff10026fe8d082bd47c4eeafaa404fedd828dd9ed5ff526c676d0a7c22c
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ **Fix**: Fix NilError when calling `fonts` for a page that has no fonts. Credit to Pavel Slabý (@paulslaby) for PR#110.
4
+
5
+ **Fix**: Fix issue #109 where nested differences between objects weren't detected properly, causing loss of data if objects (specifically images that use image masks) would merge. The fix implements a manual equality checks with up to three (3) levels of recursion, protecting against stack overflow that can be caused by the combinations of complex PDF files and Ruby's limitless recursion on `eql?`. Credit to Ryan Scott (@Subtletree) exposing the issue.
6
+
3
7
  ***
4
8
 
5
9
  #### Change log v.1.0.1
data/README.md CHANGED
@@ -18,7 +18,7 @@ Quick rundown:
18
18
 
19
19
  * When reading PDF Forms, some form data might be lost. I tried fixing this to the best of my ability, but I'm not sure it all works just yet.
20
20
 
21
- * When combining PDF Forms, form data might be unified. I couldn't fix this because this is how PDF forms work (filling a feild fills in the data in any field with the same name), but frankly, I kinda liked the issue... it's almost a feature.
21
+ * When combining PDF Forms, form data might be unified. I couldn't fix this because this is how PDF forms work (filling a field fills in the data in any field with the same name), but frankly, I kinda liked the issue... it's almost a feature.
22
22
 
23
23
  * When unifying the same TOC data more then once, one of the references will be unified with the other (meaning that if the pages look the same, both references will link to the same page instead of linking to two different pages). You can fix this by adding content to the pages before merging the PDF files (i.e. add empty text boxes to all the pages).
24
24
 
@@ -33,8 +33,12 @@ module CombinePDF
33
33
  if obj.is_a?(Hash)
34
34
  referenced = obj[:referenced_object]
35
35
  if referenced && referenced.any?
36
- # tmp = resolved[referenced.object_id] || existing[referenced]
37
- tmp = resolved[referenced.object_id] || (referenced[:raw_stream_content] && existing[referenced[:raw_stream_content]])
36
+ tmp = resolved[referenced.object_id]
37
+ if !tmp && referenced[:raw_stream_content]
38
+ tmp = existing[referenced[:raw_stream_content]]
39
+ # Avoid endless recursion by limiting it to a number of layers (default == 2)
40
+ tmp = nil unless equal_layers(tmp, referenced)
41
+ end
38
42
  if tmp
39
43
  obj[:referenced_object] = tmp
40
44
  else
@@ -339,6 +343,21 @@ module CombinePDF
339
343
 
340
344
  private
341
345
 
346
+ def equal_layers obj1, obj2, layer = 3
347
+ return true if(layer == 0)
348
+ if obj1.is_a? Hash
349
+ return false unless obj2.is_a? Hash
350
+ keys = obj1.keys;
351
+ return false if (keys - obj2.keys).any?
352
+ keys.each {|k| return false unless equal_layers( obj1[k], obj2[k], layer-1) }
353
+ elsif obj1.is_a? Array
354
+ return false unless obj2.is_a? Array
355
+ (obj1-obj2).any?
356
+ else
357
+ obj1 == obj2
358
+ end
359
+ end
360
+
342
361
  def renaming_dictionary(object = nil, dictionary = {})
343
362
  object ||= @names
344
363
  case object
@@ -253,10 +253,12 @@ module CombinePDF
253
253
  def fonts(limit_to_type0 = false)
254
254
  fonts_array = []
255
255
  pages.each do |p|
256
- p[:Resources][:Font].values.each do |f|
257
- f = f[:referenced_object] if f[:referenced_object]
258
- if (limit_to_type0 || f[:Subtype] = :Type0) && f[:Type] == :Font && !fonts_array.include?(f)
259
- fonts_array << f
256
+ if p[:Resources][:Font]
257
+ p[:Resources][:Font].values.each do |f|
258
+ f = f[:referenced_object] if f[:referenced_object]
259
+ if (limit_to_type0 || f[:Subtype] = :Type0) && f[:Type] == :Font && !fonts_array.include?(f)
260
+ fonts_array << f
261
+ end
260
262
  end
261
263
  end
262
264
  end
@@ -1,3 +1,3 @@
1
1
  module CombinePDF
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.0.2'.freeze
3
3
  end
@@ -33,6 +33,9 @@ pdf.save '03_01_nil_value_conflict.pdf'
33
33
  pdf = CombinePDF.load './Ruby/test pdfs/space_after_streram_keyword.pdf'
34
34
  pdf.save '03_02_extra_space_after_stream_keyword.pdf'
35
35
 
36
+ pdf = CombinePDF.load './Ruby/test pdfs/nested_difference.pdf'
37
+ pdf.save '03_03_nested_difference.pdf'
38
+
36
39
  pdf = CombinePDF.load './Ruby/test pdfs/names_go_haywire_0.pdf'
37
40
  pdf << CombinePDF.load('./Ruby/test pdfs/names_go_haywire_1.pdf')
38
41
  pdf.save '04_check_view_and_names_reference.pdf'
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: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2017-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4