combine_pdf 1.0.29 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 773cc37e05ad8fb02f148c12e3b7e1e24be8fc71ec946e4bca674bad107e1398
4
- data.tar.gz: ecf125185a04ecdbced0856db01514d90036f93b315ff384b3b55cc794018032
3
+ metadata.gz: e2f4eb4504ba56b707d2145c1a6e92a24c0e35c0f1fbfc8f18864585f199eefb
4
+ data.tar.gz: c9fd95a94ef49a6252907dc107ed19440fc0081855e6a86cc6c0e614fc042d9f
5
5
  SHA512:
6
- metadata.gz: d8c2636e089c11b71f4a07d29a9eea6f7df8ca1f5466c2a447e8afb2598467d2fe3663d4e382c45a04dfd6ead9f19a6afe9ae7e01fae22b8c678db08ba6d1fe8
7
- data.tar.gz: efc8160687a50fbf0df43cc5b0b85c013fc5fda3f2a053bc37716b403de18ad429caa4872832047a1ea1e2167797c0d8a5a773d8c341128752e38db9a87990ad
6
+ metadata.gz: 6edd9716fe0acccd04deff29003d666e2f7a0f4f330259fed7dd15ffcbe96eb5589b4d1ae90a04e90aaf605f78eaea021b5c4010c56061041282d36270b93454
7
+ data.tar.gz: 330775ef6008b8959e63c9a3206c5dd1da414b0f2c0e5f7d47972556a60a20e19ef27d38278fcaa4ceb097f9eb186d7200e689ecf59ea2af57940c4d2da70408
@@ -41,7 +41,7 @@ module CombinePDF
41
41
  # string:: the data to be parsed, as a String object.
42
42
  def initialize(string, options = {})
43
43
  raise TypeError, "couldn't parse data, expecting type String" unless string.is_a? String
44
- @string_to_parse = string.force_encoding(Encoding::ASCII_8BIT)
44
+ @string_to_parse = (string.frozen? ? string.dup : string).force_encoding(Encoding::ASCII_8BIT)
45
45
  @literal_strings = [].dup
46
46
  @hex_strings = [].dup
47
47
  @streams = [].dup
@@ -358,23 +358,25 @@ module CombinePDF
358
358
  ##########################################
359
359
  ## parse a Stream
360
360
  ##########################################
361
- elsif @scanner.scan(/stream[ \t]*[\r\n]/)
362
- @scanner.pos += 1 if @scanner.peek(1) == "\n".freeze && @scanner.matched[-1] != "\n".freeze
361
+ elsif @scanner.scan(/stream[ \t]*\r?\n?/)
363
362
  # advance by the publshed stream length (if any)
364
363
  old_pos = @scanner.pos
365
- if(out.last.is_a?(Hash) && out.last[:Length].is_a?(Integer) && out.last[:Length] > 2)
366
- @scanner.pos += out.last[:Length] - 2
364
+ if(out.last.is_a?(Hash) && out.last[:Length].is_a?(Integer) && out.last[:Length])
365
+ @scanner.pos += out.last[:Length]
366
+ unless(@scanner.skip(/\r?\n?endstream/))
367
+ @scanner.pos = old_pos
368
+ # raise error if the stream doesn't end.
369
+ unless @scanner.skip_until(/endstream/)
370
+ raise ParsingError, "Parsing Error: PDF file error - a stream object wasn't properly closed using 'endstream'!"
371
+ end
372
+ end
373
+ else
374
+ # raise error if the stream doesn't end.
375
+ unless @scanner.skip_until(/endstream/)
376
+ raise ParsingError, "Parsing Error: PDF file error - a stream object wasn't properly closed using 'endstream'!"
377
+ end
367
378
  end
368
379
 
369
- # the following was dicarded because some PDF files didn't have an EOL marker as required
370
- # str = @scanner.scan_until(/(\r\n|\r|\n)endstream/)
371
- # instead, a non-strict RegExp is used:
372
-
373
-
374
- # raise error if the stream doesn't end.
375
- unless @scanner.skip_until(/endstream/)
376
- raise ParsingError, "Parsing Error: PDF file error - a stream object wasn't properly closed using 'endstream'!"
377
- end
378
380
  length = @scanner.pos - (old_pos + 9)
379
381
  length = 0 if(length < 0)
380
382
  length -= 1 if(@scanner.string[old_pos + length - 1] == "\n")
@@ -52,7 +52,7 @@ module CombinePDF
52
52
  if object.length == 0 || obj_bytes.min <= 31 || obj_bytes.max >= 127 # || (obj_bytes[0] != 68 object.match(/[^D\:\d\+\-Z\']/))
53
53
  # A hexadecimal string shall be written as a sequence of hexadecimal digits (0-9 and either A-F or a-f)
54
54
  # encoded as ASCII characters and enclosed within angle brackets (using LESS-THAN SIGN (3Ch) and GREATER- THAN SIGN (3Eh)).
55
- "<#{object.unpack('H*')[0]}>".force_encoding(Encoding::ASCII_8BIT)
55
+ "<#{object.unpack('H*')[0]}>"
56
56
  else
57
57
  # a good fit for a Literal String or the string is a date (MUST be literal)
58
58
  ('(' + ([].tap { |out| obj_bytes.each { |byte| out.concat(STRING_REPLACEMENT_ARRAY[byte]) } } ).pack('C*') + ')').force_encoding(Encoding::ASCII_8BIT)
@@ -101,7 +101,7 @@ module CombinePDF
101
101
  end
102
102
  object[:indirect_reference_id] ||= 0
103
103
  object[:indirect_generation_number] ||= 0
104
- return "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} R".force_encoding(Encoding::ASCII_8BIT)
104
+ return "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} R"
105
105
  end
106
106
 
107
107
  # if the object is indirect...
@@ -109,7 +109,7 @@ module CombinePDF
109
109
  if object[:indirect_reference_id]
110
110
  object[:indirect_reference_id] ||= 0
111
111
  object[:indirect_generation_number] ||= 0
112
- out << "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} obj\n".force_encoding(Encoding::ASCII_8BIT)
112
+ out << "#{object[:indirect_reference_id]} #{object[:indirect_generation_number]} obj\n"
113
113
  if object[:indirect_without_dictionary]
114
114
  out << object_to_pdf(object[:indirect_without_dictionary])
115
115
  out << "\nendobj\n"
@@ -126,11 +126,11 @@ module CombinePDF
126
126
  # (using LESS-THAN SIGNs (3Ch) and GREATER-THAN SIGNs (3Eh)).
127
127
  out << "<<\n".b
128
128
  object.each do |key, value|
129
- out << "#{object_to_pdf key} #{object_to_pdf value}\n".force_encoding(Encoding::ASCII_8BIT) unless PDF::PRIVATE_HASH_KEYS.include? key
129
+ out << "#{object_to_pdf key} #{object_to_pdf value}\n" unless PDF::PRIVATE_HASH_KEYS.include? key
130
130
  end
131
131
  object.delete :Length
132
132
  out << '>>'.b
133
- out << "\nstream\n#{object[:raw_stream_content]}\nendstream".force_encoding(Encoding::ASCII_8BIT) if object[:raw_stream_content]
133
+ out << "\nstream\n#{object[:raw_stream_content]}\nendstream" if object[:raw_stream_content]
134
134
  out << "\nendobj\n" if object[:indirect_reference_id]
135
135
  out.join.force_encoding(Encoding::ASCII_8BIT)
136
136
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CombinePDF
4
- VERSION = '1.0.29'
4
+ VERSION = '1.0.30'
5
5
  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.29
4
+ version: 1.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-06 00:00:00.000000000 Z
11
+ date: 2025-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.3.26
140
+ rubygems_version: 3.5.22
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Combine, stamp and watermark PDF files in pure Ruby.