combine_pdf 1.0.5 → 1.0.6

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: aae99be65f85291a4eb366e78d93e015822e1dcd
4
- data.tar.gz: b92628654f3a544d3fd54fe3b9e56c344227605c
3
+ metadata.gz: b455928d3e64892b983f743f94243bd3850f1324
4
+ data.tar.gz: '0925ba5c1a7754bd54311ba499329771b0bc36b4'
5
5
  SHA512:
6
- metadata.gz: ac30f12f96a4bd58e1290859713f88917639f1ff92ba3d14ab72cfdfbdd70655727cd30a1082374fdf43e0fc8f1f502323a8b35c8f37d8a059a89baf096fb221
7
- data.tar.gz: 4e2d3f8609b1f531c95c1e28af217eaf6e93a9a112ee96e2678d562ccb7bc895b5629b56fb90e6631a891ae1fed45985ab6cafab2ec999d52a3c1e7bbfbd11e4
6
+ metadata.gz: 1a382e673cf8c042ed95638d44cb9cd804a52190bc06130ba3d9ae5a5aac564184c13c41b6a44ecbf265590a1ed3fdd97a011c252dc647502295255051fb473c
7
+ data.tar.gz: 0a77bd1af453712bcff6de7e3fbae6a745c0b3137351c8b147a614aac8d0062feee0044e66cba8e4924213ab7c9020ec5c8087fb9cc5d1258edb7303a23a919b
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # CombinePDF - the ruby way for merging PDF files
2
2
  [![Gem Version](https://badge.fury.io/rb/combine_pdf.svg)](http://badge.fury.io/rb/combine_pdf)
3
3
  [![GitHub](https://img.shields.io/badge/GitHub-Open%20Source-blue.svg)](https://github.com/boazsegev/combine_pdf)
4
+ [![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg)](https://github.com/pickhardt/maintainers-wanted)
4
5
 
5
6
  CombinePDF is a nifty model, written in pure Ruby, to parse PDF files and combine (merge) them with other PDF files, watermark them or stamp them (all using the PDF file format and pure Ruby code).
6
7
 
@@ -12,6 +13,16 @@ Install with ruby gems:
12
13
  gem install combine_pdf
13
14
  ```
14
15
 
16
+ ## Help Wanted
17
+
18
+ I need help maintaining the CombinePDF Ruby gem.
19
+
20
+ I wrote this gem because I needed to solve an issue with bates-numbering existing PDF documents. However, during the last three years or so I have been maintaining the project for no reason at all, except that I enjoyed sharing it with the community.
21
+
22
+ I love this gem, but I feel it's time I took a step back from maintaining it and concentrate on my music and other things I want to develop.
23
+
24
+ Please hit me up if you would like to join in and eventually take over.
25
+
15
26
  ## Known Limitations
16
27
 
17
28
  Quick rundown:
@@ -28,7 +28,7 @@ module CombinePDF
28
28
  rescue
29
29
  false
30
30
  end) ? load(string) : parse(string)
31
- rescue => e
31
+ rescue => _e
32
32
  raise 'General PDF error - Use CombinePDF.load or CombinePDF.parse for a non-general error message (the requested file was not found OR the string received is not a valid PDF stream OR the file was found but not valid).'
33
33
  end
34
34
  end
@@ -167,4 +167,14 @@ module CombinePDF
167
167
  def register_font_from_pdf_object(font_name, font_object)
168
168
  register_existing_font font_name, font_object
169
169
  end
170
+
171
+ # Gets the equality depth limit. This is the point at which CombinePDF will stop testing for nested items being equal.
172
+ def eq_depth_limit
173
+ @eq_depth_limit
174
+ end
175
+ # Sets the equality depth limit. This is the point at which CombinePDF will stop testing for nested items being equal.
176
+ def eq_depth_limit= value
177
+ @eq_depth_limit = value
178
+ end
179
+ @eq_depth_limit = 8
170
180
  end
@@ -147,7 +147,7 @@ module CombinePDF
147
147
  cipher.iv = encrypted[0..15]
148
148
  cipher.padding = 0
149
149
  cipher.update(encrypted[16..-1]) + cipher.final
150
- rescue StandardError => e
150
+ rescue StandardError => _e
151
151
  # puts e.class.name
152
152
  encrypted
153
153
  end
@@ -51,14 +51,14 @@ module CombinePDF
51
51
  when :FlateDecode
52
52
  raise_unsupported_error params_array[0] unless params_array[0].nil?
53
53
  if params_array[0] && params_array[0][:Predictor].to_i > 1
54
- bits = params_array[0][:BitsPerComponent] || 8
55
54
  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
55
+ # bits = params_array[0][:BitsPerComponent] || 8
56
+ # columns = params_array[0][:Columns] || 1
57
+ if (2..9).cover? predictor
58
58
  ####
59
59
  # prepare TIFF group
60
60
  raise_unsupported_error params_array[0]
61
- elsif (10..15).cover? params_array[0][:Predictor].to_i == 2
61
+ elsif (10..15).cover? predictor
62
62
  ####
63
63
  # prepare PNG group
64
64
  raise_unsupported_error params_array[0]
@@ -389,7 +389,7 @@ module CombinePDF
389
389
  until scanner.eos?
390
390
  if do_scan
391
391
  while do_scan && !scanner.eos?
392
- if scanner.scan(/[\<]?[\d\w]+[\>]?/)
392
+ if scanner.scan(/[\<]?[\w]+[\>]?/)
393
393
  if scanner.matched[0] == '<'
394
394
  lines_found.last << scanner.matched[1..-2]
395
395
  else
@@ -63,9 +63,9 @@ module CombinePDF
63
63
  # setup references to avoid method calls.
64
64
  local_res = resources
65
65
  local_val = nil
66
- # setup references to avoid method calls.
67
- remote_res = obj.resources
68
- remote_val = nil
66
+ # # setup references to avoid method calls.
67
+ # remote_res = obj.resources
68
+ # remote_val = nil
69
69
 
70
70
  # add each of the new resources in the uncoming Page to the local resource Hash
71
71
  obj.resources.each do |key, new_val|
@@ -493,19 +493,19 @@ module CombinePDF
493
493
 
494
494
  # rotate the page 90 degrees counter clockwise
495
495
  def rotate_left
496
- self[:Rotate] = self[:Rotate].to_f + 90
496
+ self[:Rotate] = (self[:Rotate].to_f() + 90)
497
497
  fix_rotation
498
498
  end
499
499
 
500
500
  # rotate the page 90 degrees clockwise
501
501
  def rotate_right
502
- self[:Rotate] = self[:Rotate].to_f - 90
502
+ self[:Rotate] = (self[:Rotate].to_f() - 90)
503
503
  fix_rotation
504
504
  end
505
505
 
506
506
  # rotate the page by 180 degrees
507
507
  def rotate_180
508
- self[:Rotate] = self[:Rotate].to_f +180
508
+ self[:Rotate] = (self[:Rotate].to_f() + 180)
509
509
  fix_rotation
510
510
  end
511
511
 
@@ -816,9 +816,9 @@ module CombinePDF
816
816
  out = []
817
817
  scanner = StringScanner.new text
818
818
  until scanner.eos?
819
- if scanner.scan /[#{rtl_characters} ]/
819
+ if scanner.scan(/[#{rtl_characters} ]/)
820
820
  out.unshift scanner.matched
821
- elsif scanner.scan /[^#{rtl_characters}]+/
821
+ elsif scanner.scan(/[^#{rtl_characters}]+/)
822
822
  if out.empty? && scanner.matched.match(/[\s]$/) && !scanner.eos?
823
823
  white_space_to_move = scanner.matched.match(/[\s]+$/).to_s
824
824
  out.unshift scanner.matched[0..-1 - white_space_to_move.length]
@@ -65,11 +65,11 @@ module CombinePDF
65
65
  @scanner = StringScanner.new @string_to_parse
66
66
  @scanner.pos = 0
67
67
  @scanner.skip(/[^%]*/) if @scanner.exist?(/%PDF/i)
68
- if @scanner.scan /\%PDF\-[\d\-\.]+/
68
+ if @scanner.scan(/\%PDF\-[\d\-\.]+/)
69
69
  @version = @scanner.matched.scan(/[\d\.]+/)[0].to_f
70
70
  loop do
71
71
  break unless @scanner.scan(/[^\d\r\n]+/)
72
- break if @scanner.check(/([\d]+[\s]+[\d]+[\s]+obj[\n\r\s]+\<\<)|([\n\r]+)/)
72
+ break if @scanner.check(/([\d]+[\s]+[\d]+[\s]+obj[\s]+\<\<)|([\n\r]+)/)
73
73
  break if @scanner.eos?
74
74
  @scanner.pos += 1
75
75
  end
@@ -381,7 +381,7 @@ module CombinePDF
381
381
  # is a comment, skip until new line
382
382
  loop do
383
383
  # break unless @scanner.scan(/[^\d\r\n]+/)
384
- break if @scanner.check(/([\d]+[\s]+[\d]+[\s]+obj[\n\r\s]+\<\<)|([\n\r]+)/) || @scanner.eos? # || @scanner.scan(/[^\d]+[\r\n]+/) ||
384
+ break if @scanner.check(/([\d]+[\s]+[\d]+[\s]+obj[\s]+\<\<)|([\n\r]+)/) || @scanner.eos? # || @scanner.scan(/[^\d]+[\r\n]+/) ||
385
385
  @scanner.scan(/[^\d\r\n]+/) || @scanner.pos += 1
386
386
  end
387
387
  # puts "AFTER COMMENT: #{@scanner.peek 8}"
@@ -20,8 +20,6 @@ module CombinePDF
20
20
  #
21
21
  # this is used for internal operations, such as injectng data using the << operator.
22
22
  def add_referenced()
23
- # add references but not root
24
- dup_pages = nil
25
23
  # an existing object map
26
24
  resolved = {}.dup
27
25
  existing = {}.dup
@@ -156,7 +154,7 @@ module CombinePDF
156
154
  # there is no point is calling the method before preparing the output.
157
155
  def rebuild_catalog_and_objects
158
156
  catalog = rebuild_catalog
159
- page_objects = catalog[:Pages][:referenced_object][:Kids].map { |e| @objects << e[:referenced_object]; e[:referenced_object] }
157
+ catalog[:Pages][:referenced_object][:Kids].each { |e| @objects << e[:referenced_object]; e[:referenced_object] }
160
158
  # adds every referenced object to the @objects (root), addition is performed as pointers rather then copies
161
159
  add_referenced()
162
160
  catalog
@@ -339,12 +337,12 @@ module CombinePDF
339
337
  end
340
338
  end
341
339
  formatted_outline_str << "\n" * 10
342
- File.open(file, 'w') { |file| file.write(formatted_outline_str) }
340
+ File.open(file, 'w') { |f| f.write(formatted_outline_str) }
343
341
  end
344
342
 
345
343
  private
346
344
 
347
- def equal_layers obj1, obj2, layer = 3
345
+ def equal_layers obj1, obj2, layer = CombinePDF.eq_depth_limit
348
346
  return true if(layer == 0)
349
347
  return true if obj1.object_id == obj2.object_id
350
348
  if obj1.is_a? Hash
@@ -275,7 +275,7 @@ module CombinePDF
275
275
  # pdf.save "both_files_merged.pdf"
276
276
  # data:: is PDF page (Hash), and Array of PDF pages or a parsed PDF object to be added.
277
277
  def <<(data)
278
- insert -1, data
278
+ insert(-1, data)
279
279
  end
280
280
 
281
281
  # add the pages (or file) to the BEGINNING of the PDF (combine/merge) and RETURNS SELF for nesting operators.
@@ -42,7 +42,7 @@ module CombinePDF
42
42
 
43
43
  def format_string_to_pdf(object)
44
44
  # object.force_encoding(Encoding::ASCII_8BIT)
45
- if !object.match(/[^D\:\d\+\-\Z\']/) # if format is set to Literal and string isn't a date
45
+ if !object.match(/[^D\:\d\+\-Z\']/) # if format is set to Literal and string isn't a date
46
46
  ('(' + ([].tap { |out| object.bytes.to_a.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)
47
47
  else
48
48
  # A hexadecimal string shall be written as a sequence of hexadecimal digits (0–9 and either A–F or a–f)
@@ -1,3 +1,3 @@
1
1
  module CombinePDF
2
- VERSION = '1.0.5'.freeze
2
+ VERSION = '1.0.6'.freeze
3
3
  end
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $VERBOSE = true
4
+
3
5
  require 'benchmark'
4
6
  $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), __FILE__)
5
7
  require 'combine_pdf'
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $VERBOSE = true
4
+
3
5
  require 'benchmark'
4
6
  $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), __FILE__)
5
7
  require 'combine_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.5
4
+ version: 1.0.6
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-07-14 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4