combine_pdf 1.0.16 → 1.0.18

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
  SHA256:
3
- metadata.gz: d071703a8903bc5a11d7beb5a0bcb284a8bced5763705de3a7dd9ae6be35b64d
4
- data.tar.gz: 898069ad7ec79ad4fadea5383a721f28c5dfc3632fc20aaa40624954bfe70170
3
+ metadata.gz: 95f44419c731c5b1e7625589d159c608ab6948004e347db9ee2380611e10dd6f
4
+ data.tar.gz: d2ee8cf53e111cdf4051886262ad2a4fa216eca36aaaf1b45b7782379f793642
5
5
  SHA512:
6
- metadata.gz: d52868ff7a021801207ff17a1e87aca8fa1bd82e6fd0dacf91d39d57695b07b87238898238fa90755bfaaec65cb4df384b6db97f3f4e3bf70da7d3d808e55daa
7
- data.tar.gz: f68133d14d5eb5f0428097b4421976da49471eed61f4ac0e574c4718b588458f6971fd107ccc397be004997f3c31ac6bfc122675992412fd521a7910d6f2abd9
6
+ metadata.gz: 7cac17e8c080e0eba10f19efa90c5eb6252f12811218ff5ad8f330ec8977abec677628d6cfaf70d9abc5e2b754e711e9024315cad0de2f32286f1d7dbeabec87
7
+ data.tar.gz: 7e60b19afafa071a6d21ce73da4be142501c0becc4aede5e579706789d0c276903a8193661d0ffa16d0c4c906d0fa6136124011d1de3a8c968a3c1334804d476
@@ -2,6 +2,14 @@
2
2
 
3
3
  ***
4
4
 
5
+ #### Change log v.1.0.18
6
+
7
+ **Fix**: fixed issue with the 1.0.17 release where `ProcSet` PDF Arrays should have been expected but where ignored and a PDF Object was assumed instead (issue #171) - credit to @chuchiperriman (Jesús Barbero Rodríguez).
8
+
9
+ #### Change log v.1.0.17
10
+
11
+ **Fix**: fixed issue where nested structure equality tests might provide false positives, resulting in lost data (issue #166) - credit to @cschilbe (Conrad Schilbe).
12
+
5
13
  #### Change log v.1.0.16
6
14
 
7
15
  **Fix**: some documentation typos were fixed (PR #147) - credit to @djhopper01 (Derek Hopper).
data/README.md CHANGED
@@ -41,6 +41,8 @@ Quick rundown:
41
41
 
42
42
  * Sometimes the CombinePDF will raise an exception even if the PDF could be parsed (i.e., when PDF optional content exists)... I find it better to err on the side of caution, although for optional content PDFs an exception is avoidable using `CombinePDF.load(pdf_file, allow_optional_content: true)`.
43
43
 
44
+ * The CombinePDF gem runs recursive code to both parse and format the PDF files. Hence, PDF files that have heavily nested objects, as well as those that where combined in a way that results in cyclic nesting, might explode the stack - resulting in an exception or program failure.
45
+
44
46
  CombinePDF is written natively in Ruby and should (presumably) work on all Ruby platforms that follow Ruby 2.0 compatibility.
45
47
 
46
48
  However, PDF files are quite complex creatures and no guaranty is provided.
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'ruby-rc4', '>= 0.1.5'
22
22
 
23
23
  # spec.add_development_dependency "bundler", ">= 1.7"
24
- spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rake", ">= 12.3.3"
25
25
  spec.add_development_dependency "minitest"
26
26
  end
@@ -5,6 +5,7 @@ require 'securerandom'
5
5
  require 'strscan'
6
6
  require 'matrix'
7
7
  require 'set'
8
+ require 'digest'
8
9
 
9
10
  # require the RC4 Gem
10
11
  require 'rc4'
@@ -94,7 +94,7 @@ module CombinePDF
94
94
  # end
95
95
 
96
96
  # set ProcSet to recommended value
97
- resources[:ProcSet] = [:PDF, :Text, :ImageB, :ImageC, :ImageI] # this was recommended by the ISO. 32000-1:2008
97
+ resources[:ProcSet] ||= [:PDF, :Text, :ImageB, :ImageC, :ImageI] # this was recommended by the ISO. 32000-1:2008
98
98
 
99
99
  if top # if this is a stamp (overlay)
100
100
  insert_content CONTENT_CONTAINER_START, 0
@@ -147,7 +147,7 @@ module CombinePDF
147
147
 
148
148
  # This method adds a simple text box to the Page represented by the PDFWriter class.
149
149
  # This function takes two values:
150
- # text:: the text to potin the box.
150
+ # text:: the text to write in the box.
151
151
  # properties:: a Hash of box properties.
152
152
  # the symbols and values in the properties Hash could be any or all of the following:
153
153
  # x:: the left position of the box.
@@ -233,16 +233,18 @@ module CombinePDF
233
233
  # all characters that aren't white space or special: /[^\x00\x09\x0a\x0c\x0d\x20\x28\x29\x3c\x3e\x5b\x5d\x7b\x7d\x2f\x25]+
234
234
  elsif str = @scanner.scan(/\/[^\x00\x09\x0a\x0c\x0d\x20\x28\x29\x3c\x3e\x5b\x5d\x7b\x7d\x2f\x25]*/)
235
235
  out << (str[1..-1].gsub(/\#[0-9a-fA-F]{2}/) { |a| a[1..2].hex.chr }).to_sym
236
+ # warn "CombinePDF detected name: #{out.last.to_s}"
236
237
  ##########################################
237
238
  ## Parse a Number
238
239
  ##########################################
239
240
  elsif str = @scanner.scan(/[\+\-\.\d]+/)
240
241
  str =~ /\./ ? (out << str.to_f) : (out << str.to_i)
242
+ # warn "CombinePDF detected number: #{out.last.to_s}"
241
243
  ##########################################
242
244
  ## parse a Hex String
243
245
  ##########################################
244
246
  elsif str = @scanner.scan(/\<[0-9a-fA-F]*\>/)
245
- # warn "Found a hex string"
247
+ # warn "Found a hex string #{str}"
246
248
  str = str.slice(1..-2).force_encoding(Encoding::ASCII_8BIT)
247
249
  # str = "0#{str}" if str.length.odd?
248
250
  out << unify_string([str].pack('H*').force_encoding(Encoding::ASCII_8BIT))
@@ -336,6 +338,7 @@ module CombinePDF
336
338
  end
337
339
  end
338
340
  out << unify_string(str.pack('C*').force_encoding(Encoding::ASCII_8BIT))
341
+ # warn "Found Literal String: #{out.last}"
339
342
  ##########################################
340
343
  ## parse a Dictionary
341
344
  ##########################################
@@ -348,6 +351,7 @@ module CombinePDF
348
351
  ## return content of array or dictionary
349
352
  ##########################################
350
353
  elsif @scanner.scan(/\]/) || @scanner.scan(/>>/)
354
+ # warn "Dictionary / Array ended with #{@scanner.peek(5)}"
351
355
  return out
352
356
  ##########################################
353
357
  ## parse a Stream
@@ -364,6 +368,8 @@ module CombinePDF
364
368
  raise ParsingError, "Parsing Error: PDF file error - a stream object wasn't properly closed using 'endstream'!"
365
369
  end
366
370
 
371
+ # warn "CombinePDF parser: detected Stream #{str.length} bytes long #{str[0..3]}...#{str[-4..-1]}"
372
+
367
373
  # need to remove end of stream
368
374
  if out.last.is_a? Hash
369
375
  # out.last[:raw_stream_content] = str[0...-10] #cuts only one EON char (\n or \r)
@@ -528,6 +534,14 @@ module CombinePDF
528
534
  inheritance_hash[:Resources] ||= { referenced_object: {}, is_reference_only: true }.dup
529
535
  (inheritance_hash[:Resources][:referenced_object] || inheritance_hash[:Resources]).update((catalogs[:Resources][:referenced_object] || catalogs[:Resources]), &HASH_UPDATE_PROC_FOR_OLD)
530
536
  end
537
+ if catalogs[:ProcSet].is_a?(Array)
538
+ if(inheritance_hash[:ProcSet])
539
+ inheritance_hash[:ProcSet][:referenced_object].concat(catalogs[:ProcSet])
540
+ inheritance_hash[:ProcSet][:referenced_object].uniq!
541
+ else
542
+ inheritance_hash[:ProcSet] ||= { referenced_object: catalogs[:ProcSet], is_reference_only: true }.dup
543
+ end
544
+ end
531
545
  if catalogs[:ColorSpace]
532
546
  inheritance_hash[:ColorSpace] ||= { referenced_object: {}, is_reference_only: true }.dup
533
547
  (inheritance_hash[:ColorSpace][:referenced_object] || inheritance_hash[:ColorSpace]).update((catalogs[:ColorSpace][:referenced_object] || catalogs[:ColorSpace]), &HASH_UPDATE_PROC_FOR_OLD)
@@ -556,6 +570,18 @@ module CombinePDF
556
570
  catalogs[:ColorSpace] = { referenced_object: catalogs[:ColorSpace], is_reference_only: true } unless catalogs[:ColorSpace][:referenced_object]
557
571
  catalogs[:ColorSpace][:referenced_object].update((inheritance_hash[:ColorSpace][:referenced_object] || inheritance_hash[:ColorSpace]), &HASH_UPDATE_PROC_FOR_OLD)
558
572
  end
573
+ if inheritance_hash[:ProcSet]
574
+ if(catalogs[:ProcSet])
575
+ if catalogs[:ProcSet].is_a?(Array)
576
+ catalogs[:ProcSet] = { referenced_object: catalogs[:ProcSet], is_reference_only: true }
577
+ end
578
+ catalogs[:ProcSet][:referenced_object].concat(inheritance_hash[:ProcSet][:referenced_object])
579
+ catalogs[:ProcSet][:referenced_object].uniq!
580
+ else
581
+ catalogs[:ProcSet] = { is_reference_only: true }.dup
582
+ catalogs[:ProcSet][:referenced_object] = catalogs[:ProcSet][:referenced_object].dup
583
+ end
584
+ end
559
585
  # (catalogs[:ColorSpace] ||= {}).update(inheritance_hash[:ColorSpace], &HASH_UPDATE_PROC_FOR_OLD) if inheritance_hash[:ColorSpace]
560
586
  # catalogs[:Order] ||= inheritance_hash[:Order] if inheritance_hash[:Order]
561
587
  # catalogs[:AS] ||= inheritance_hash[:AS] if inheritance_hash[:AS]
@@ -373,16 +373,19 @@ module CombinePDF
373
373
  private
374
374
 
375
375
  def equal_layers obj1, obj2, layer = CombinePDF.eq_depth_limit
376
- return true if(layer == 0)
377
376
  return true if obj1.object_id == obj2.object_id
378
377
  if obj1.is_a? Hash
379
378
  return false unless obj2.is_a? Hash
379
+ return false unless obj1.length == obj2.length
380
380
  keys = obj1.keys;
381
- return false if (keys - obj2.keys).any?
381
+ keys2 = obj2.keys;
382
+ return false if (keys - keys2).any? || (keys2 - keys).any?
383
+ return (warn("CombinePDF nesting limit reached") || true) if(layer == 0)
382
384
  keys.each {|k| return false unless equal_layers( obj1[k], obj2[k], layer-1) }
383
385
  elsif obj1.is_a? Array
384
386
  return false unless obj2.is_a? Array
385
- (obj1-obj2).any?
387
+ return false unless obj1.length == obj2.length
388
+ (obj1-obj2).any? || (obj2-obj1).any?
386
389
  else
387
390
  obj1 == obj2
388
391
  end
@@ -1,3 +1,3 @@
1
1
  module CombinePDF
2
- VERSION = '1.0.16'.freeze
2
+ VERSION = '1.0.18'.freeze
3
3
  end
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.16
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-22 00:00:00.000000000 Z
11
+ date: 2020-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
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: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.0.1
107
+ rubygems_version: 3.1.2
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Combine, stamp and watermark PDF files in pure Ruby.