combine_pdf 1.0.23 → 1.0.25

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: 94a057a85d5c2709211baa3ed7d7deaf73fe93d6bb39ef76e0441a166fb36926
4
- data.tar.gz: c7dc7060c7abd51d84ee871b5f818d6e23a797eb424a8a7a963b0ae7f7324921
3
+ metadata.gz: 54586af58c21708b23e6c368b9a0841b4363ebd8113103d9d37deb045032485f
4
+ data.tar.gz: 121335c835d1902872e6b53de3b8bfc798dce9c83c0fdfaa0927c47e2771d0cc
5
5
  SHA512:
6
- metadata.gz: 110074ae751586009d436dd4dc997c7d6bb71480d782270fe67834458cecc7479b58effc8102745a437c718426c97ca78d9ea3d2941355ba1ce8fc6f34ab2b8a
7
- data.tar.gz: 4cf409946ba651fd474f7ff8a3dbf56442afd96b35fe73b68013a9a863e01e9d766a516ea4ddd4f5af7f2c47192abc0619321a6bc01c5a4e0dcd0e192701d168
6
+ metadata.gz: a52629b113303a5df9000ac65d33fa5d7843ee74d8977ee7005ae43a476e63917fb462265915b25f8b5b7c6e902cf9a0f4d36f504dbc47651015c058b322c96b
7
+ data.tar.gz: 6fb00ab0f0ad9e482a850402e83183e9c1fbc0603093d069930a42ba51d704a4cad5cfb8086a27123cbe06f8b735dade401dc014b843b542cb8b1f84d0a680e0
@@ -0,0 +1,28 @@
1
+ name: Main
2
+ on:
3
+ push:
4
+
5
+ jobs:
6
+ tests:
7
+ name: Tests
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby: ["2.7", "3.0", "3.1", "3.2"]
13
+
14
+ steps:
15
+ - name: Checkout code
16
+ uses: actions/checkout@v3
17
+
18
+ - name: Setup Ruby
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: true
23
+
24
+ - name: Generate lockfile
25
+ run: bundle lock
26
+
27
+ - name: Run tests
28
+ run: bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Change Log
2
2
 
3
- #### Change log v.1.0.23 (2023-03-04)
3
+ #### Change log v.1.0.25 (2023-12-19)
4
+
5
+ **Fix**: possible improve memory usage. Credit to @denislavski (Denislav Naydenov) for opening PR #223 and suggesting this change.
6
+
7
+ #### Change log v.1.0.24 (2023-10-19)
8
+
9
+ **Fix**: possible `nil` in loop. Credit to @jkowens for PR #231 and adding a quick fix using a simple guard.
10
+
11
+ **Fix**: preserve file creation date metadata where relevant.
12
+
13
+ #### Change log v.1.0.23 (2023-04-04)
4
14
 
5
15
  **Feature**: merged PR #177 for the `raise_on_encrypted: true` option support. Credit to @leviwilson and @kimyu92 for the PR.
6
16
 
data/combine_pdf.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "combine_pdf"
8
8
  spec.version = CombinePDF::VERSION
9
9
  spec.authors = ["Boaz Segev"]
10
- spec.email = ["boaz@2be.co.il"]
10
+ spec.email = ["bo@bowild.com"]
11
11
  spec.summary = %q{Combine, stamp and watermark PDF files in pure Ruby.}
12
12
  spec.description = %q{A nifty gem, in pure Ruby, to parse PDF files and combine (merge) them with other PDF files, number the pages, watermark them or stamp them, create tables, add basic text objects etc` (all using the PDF file format).}
13
13
  spec.homepage = "https://github.com/boazsegev/combine_pdf"
@@ -323,8 +323,8 @@ module CombinePDF
323
323
  str << 12
324
324
  when 48..57 # octal notation for byte?
325
325
  rep -= 48
326
- rep = (rep << 3) + (str_bytes.shift-48) if str_bytes[0].between?(48, 57)
327
- rep = (rep << 3) + (str_bytes.shift-48) if str_bytes[0].between?(48, 57) && (((rep << 3) + (str_bytes[0] - 48)) <= 255)
326
+ rep = (rep << 3) + (str_bytes.shift-48) if str_bytes[0]&.between?(48, 57)
327
+ rep = (rep << 3) + (str_bytes.shift-48) if str_bytes[0]&.between?(48, 57) && (((rep << 3) + (str_bytes[0] - 48)) <= 255)
328
328
  str << rep
329
329
  when 10 # new line, ignore
330
330
  str_bytes.shift if str_bytes[0] == 13
@@ -175,8 +175,12 @@ module CombinePDF
175
175
  def to_pdf(options = {})
176
176
  # reset version if not specified
177
177
  @version = 1.5 if @version.to_f == 0.0
178
+
178
179
  # set info for merged file
179
- @info[:ModDate] = @info[:CreationDate] = Time.now.strftime "D:%Y%m%d%H%M%S%:::z'00"
180
+ unless(@info[:CreationDate].is_a?(String))
181
+ @info[:CreationDate] = Time.now unless @info[:CreationDate].is_a?(Time)
182
+ @info[:CreationDate] = @info[:CreationDate].getgm.strftime("D:%Y%m%d%H%M%S%:::z'00")
183
+ end
180
184
  @info[:Subject] = options[:subject] if options[:subject]
181
185
  @info[:Producer] = options[:producer] if options[:producer]
182
186
  # rebuild_catalog
@@ -202,9 +206,9 @@ module CombinePDF
202
206
  xref_location = loc
203
207
  # xref_location = 0
204
208
  # out.each { |line| xref_location += line.bytesize + 1}
205
- out << "xref\n0 #{indirect_object_count}\n0000000000 65535 f \n"
206
- xref.each { |offset| out << (out.pop + ("%010d 00000 n \n" % offset)) }
207
- out << out.pop + 'trailer'
209
+ out << "xref\n0 #{indirect_object_count}\n0000000000 65535 f "
210
+ xref.each { |offset| out << ("%010d 00000 n " % offset) }
211
+ out << 'trailer'.freeze
208
212
  out << "<<\n/Root #{false || "#{catalog[:indirect_reference_id]} #{catalog[:indirect_generation_number]} R"}"
209
213
  out << "/Size #{indirect_object_count}"
210
214
  out << "/Info #{@info[:indirect_reference_id]} #{@info[:indirect_generation_number]} R"
@@ -1,3 +1,3 @@
1
1
  module CombinePDF
2
- VERSION = '1.0.23'.freeze
2
+ VERSION = '1.0.25'.freeze
3
3
  end
data/test/automated CHANGED
@@ -3,7 +3,8 @@
3
3
  $VERBOSE = true
4
4
 
5
5
  require 'benchmark'
6
- $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), __FILE__)
6
+ Dir.chdir File.expand_path(File.join('..', '..', 'lib'), __FILE__)
7
+ $LOAD_PATH.unshift Dir.pwd
7
8
  require 'combine_pdf'
8
9
  # require 'bundler/setup'
9
10
 
@@ -15,51 +16,51 @@ require 'combine_pdf'
15
16
  # Pry.start
16
17
 
17
18
  pdf = CombinePDF.load "../../test\ pdfs/filled_form.pdf"
18
- pdf.save '01_check_radio_buttuns.pdf'
19
+ pdf.save '../tmp/01_check_radio_buttuns.pdf'
19
20
  pdf = CombinePDF.load "../../test\ pdfs/filled_form.pdf"
20
21
  pdf << CombinePDF.load("../../test\ pdfs/empty_form.pdf")
21
22
  pdf << CombinePDF.load("../../test\ pdfs/filled_form.pdf")
22
- pdf.save '02_check_form_unification_middle_is_empty.pdf'
23
+ pdf.save '../tmp/02_check_form_unification_middle_is_empty.pdf'
23
24
 
24
25
  pdf = CombinePDF.load "../../test\ pdfs/check_form_data__objstreams_w_versions.pdf"
25
- pdf.save '02_01_check_form_data_ordering_issue.pdf'
26
+ pdf.save '../tmp/02_01_check_form_data_ordering_issue.pdf'
26
27
 
27
28
 
28
29
  pdf = CombinePDF.load '../../test pdfs/share-font-background.pdf'
29
30
  pdf2 = CombinePDF.load '../../test pdfs/share-font-foreground.pdf'
30
31
  i = 0
31
32
  pdf.pages.each { |pg| pg << pdf2.pages[i] }
32
- pdf.save '03_check_font_conflict.pdf'
33
+ pdf.save '../tmp/03_check_font_conflict.pdf'
33
34
 
34
35
  pdf = CombinePDF.load '../../test pdfs/nil_1.pdf'
35
36
  pdf2 = CombinePDF.load '../../test pdfs/nil_2.pdf'
36
37
  pdf << pdf2
37
- pdf.save '03_01_nil_value_conflict.pdf'
38
+ pdf.save '../tmp/03_01_nil_value_conflict.pdf'
38
39
 
39
40
  pdf = CombinePDF.load '../../test pdfs/space_after_streram_keyword.pdf'
40
- pdf.save '03_02_extra_space_after_stream_keyword.pdf'
41
+ pdf.save '../tmp/03_02_extra_space_after_stream_keyword.pdf'
41
42
 
42
43
  pdf = CombinePDF.load '../../test pdfs/nested_difference.pdf'
43
- pdf.save '03_03_nested_difference.pdf'
44
+ pdf.save '../tmp/03_03_nested_difference.pdf'
44
45
 
45
46
  pdf = CombinePDF.load '../../test pdfs/names_go_haywire_0.pdf'
46
47
  pdf << CombinePDF.load('../../test pdfs/names_go_haywire_1.pdf')
47
- pdf.save '04_check_view_and_names_reference.pdf'
48
+ pdf.save '../tmp/04_check_view_and_names_reference.pdf'
48
49
 
49
50
  pdf = CombinePDF.load('../../test pdfs/outlines/self_merge_err.pdf')
50
- pdf.save '05_x1_scribus_test.pdf'
51
+ pdf.save '../tmp/05_x1_scribus_test.pdf'
51
52
  pdf = CombinePDF.load('../../test pdfs/outlines/self_merge_err.pdf')
52
53
  pdf << CombinePDF.load('../../test pdfs/outlines/self_merge_err.pdf')
53
- pdf.save '05_x2_scribus_test.pdf'
54
+ pdf.save '../tmp/05_x2_scribus_test.pdf'
54
55
  pdf = CombinePDF.load "../../test pdfs/outlines/named_dest.pdf";nil
55
- pdf.save '05_check_named_dest_links.pdf' # this will take a while
56
+ pdf.save '../tmp/05_check_named_dest_links.pdf' # this will take a while
56
57
  pdf = CombinePDF.load "../../test pdfs/outlines/named_dest.pdf";nil
57
58
  pdf << CombinePDF.load('../../test pdfs/outlines/named_dest.pdf'); nil
58
- pdf.save '05_1_timeless_check_named_dest_links.pdf' # never ends... :-(
59
+ pdf.save '../tmp/05_1_timeless_check_named_dest_links.pdf' # never ends... :-(
59
60
 
60
61
  pdf = CombinePDF.load '../../test pdfs/outline_small.pdf'
61
62
  pdf << CombinePDF.load('../../test pdfs/outline_small.pdf')
62
- pdf.save '06_check_links_to_second_copy.pdf'
63
+ pdf.save '../tmp/06_check_links_to_second_copy.pdf'
63
64
 
64
65
  lists = %w(../../test\ pdfs/outlines/self_merge_err.pdf ../../test\ pdfs/outlines/big_toc.pdf ../../test\ pdfs/outlines/bigger_toc.pdf ../../test\ pdfs/outlines/named_dest_no_toc.pdf ../../test\ pdfs/outlines/named_dest_no_toc2.pdf ../../test\ pdfs/outlines/named_dest.pdf ../../test\ pdfs/outlines/named_dest2.pdf)
65
66
 
@@ -76,7 +77,7 @@ lists.each do |n|
76
77
  end
77
78
  pdf = CombinePDF.new
78
79
  lists.each { |n| pdf << CombinePDF.load(n) }
79
- pdf.save('07_named destinations.pdf')
80
+ pdf.save('../tmp/07_named destinations.pdf')
80
81
 
81
82
  pdf = CombinePDF.new
82
83
  lists.each { |n| pdf << CombinePDF.load(n) }
@@ -90,15 +91,15 @@ pdf.number_pages(start_at: 1,
90
91
  number_location: [:top, :bottom],
91
92
  opacity: 0.75)
92
93
 
93
- pdf.save('07_named destinations_numbered.pdf')
94
+ pdf.save('../tmp/07_named destinations_numbered.pdf')
94
95
 
95
- CombinePDF.load("../../test\ pdfs/Scribus-unknown_err.pdf").save '08_1-unknown-err-empty-str.pdf'
96
- CombinePDF.load("../../test\ pdfs/Scribus-unknown_err2.pdf").save '08_2-unknown-err-empty-str.pdf'
97
- CombinePDF.load("../../test\ pdfs/Scribus-unknown_err3.pdf").save '08_3-unknown-err-empty-str.pdf'
98
- CombinePDF.load("../../test\ pdfs/xref_in_middle.pdf").save '08_4-xref-in-middle.pdf'
99
- CombinePDF.load("../../test\ pdfs/xref_split.pdf").save '08_5-xref-fragmented.pdf'
96
+ CombinePDF.load("../../test\ pdfs/Scribus-unknown_err.pdf").save '../tmp/08_1-unknown-err-empty-str.pdf'
97
+ CombinePDF.load("../../test\ pdfs/Scribus-unknown_err2.pdf").save '../tmp/08_2-unknown-err-empty-str.pdf'
98
+ CombinePDF.load("../../test\ pdfs/Scribus-unknown_err3.pdf").save '../tmp/08_3-unknown-err-empty-str.pdf'
99
+ CombinePDF.load("../../test\ pdfs/xref_in_middle.pdf").save '../tmp/08_4-xref-in-middle.pdf'
100
+ CombinePDF.load("../../test\ pdfs/xref_split.pdf").save '../tmp/08_5-xref-fragmented.pdf'
100
101
 
101
- CombinePDF.load("../../test\ pdfs/nil_object.pdf").save('09_nil_in_parsed_array.pdf')
102
+ CombinePDF.load("../../test\ pdfs/nil_object.pdf").save('../tmp/09_nil_in_parsed_array.pdf')
102
103
 
103
104
  encrypted = [ "../../test\ pdfs/pdf-reader/encrypted_version4_revision4_128bit_aes_user_pass_apples_enc_metadata.pdf",
104
105
  "../../test\ pdfs/AESv2\ encrypted.pdf",
@@ -109,7 +110,7 @@ encrypted = [ "../../test\ pdfs/pdf-reader/encrypted_version4_revision4_128bit_a
109
110
  encrypted.length.times do |i|
110
111
  fname = File.basename encrypted[i]
111
112
  begin
112
- CombinePDF.load(encrypted[i]).save "10_#{i}_#{fname}"
113
+ CombinePDF.load(encrypted[i]).save "../tmp/10_#{i}_#{fname}"
113
114
  rescue => e
114
115
  puts e.class.name, e.message
115
116
  if(i == 0)
@@ -125,10 +126,10 @@ IO.binwrite '11_prawn.pdf', (Prawn::Document.new { text 'Hello World!' }).render
125
126
  page = CombinePDF.parse((Prawn::Document.new { text 'Hello World!' }).render)
126
127
  pdf = CombinePDF.new
127
128
  pdf << page
128
- pdf.save '11_parsed_from_prawn.pdf'
129
+ pdf.save '../tmp/11_parsed_from_prawn.pdf'
129
130
  pdf = CombinePDF.new
130
131
  pdf << page << page
131
- pdf.save('11_AcrobatReader_is_unique_page.pdf')
132
+ pdf.save('../tmp/11_AcrobatReader_is_unique_page.pdf')
132
133
 
133
134
  puts GC.stat.inspect
134
135
  # unify = [
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.23
4
+ version: 1.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2023-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4
@@ -84,11 +84,12 @@ description: A nifty gem, in pure Ruby, to parse PDF files and combine (merge) t
84
84
  with other PDF files, number the pages, watermark them or stamp them, create tables,
85
85
  add basic text objects etc` (all using the PDF file format).
86
86
  email:
87
- - boaz@2be.co.il
87
+ - bo@bowild.com
88
88
  executables: []
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
+ - ".github/workflows/main.yml"
92
93
  - ".gitignore"
93
94
  - ".travis.yml"
94
95
  - CHANGELOG.md