combine_pdf 0.0.9 → 0.0.11

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.
@@ -15,10 +15,12 @@ module CombinePDF
15
15
  #
16
16
  # this Hash lists the private Hash keys that the CombinePDF library uses to
17
17
  # differentiate between complex PDF objects.
18
- PRIVATE_HASH_KEYS = [:indirect_reference_id, :indirect_generation_number, :raw_stream_content, :is_reference_only, :referenced_object, :indirect_without_dictionary]
18
+ PRIVATE_HASH_KEYS = [:indirect_reference_id, :indirect_generation_number, :raw_stream_content, :is_reference_only, :referenced_object, :indirect_without_dictionary, :linked_fonts]
19
19
  #@private
20
20
  #:nodoc: all
21
21
 
22
+ protected
23
+
22
24
 
23
25
  # This is an internal class. you don't need it.
24
26
  module PDFOperations
@@ -106,10 +108,13 @@ module CombinePDF
106
108
  resources.each do |k,v|
107
109
  if v.is_a?(Hash)
108
110
  new_dictionary = {}
111
+ new_name = "Combine" + SecureRandom.urlsafe_base64() + "PDF"
112
+ i = 1
109
113
  v.each do |old_key, value|
110
- new_key = ("CombinePDF" + SecureRandom.urlsafe_base64(9)).to_sym
114
+ new_key = (new_name + i.to_s).to_sym
111
115
  names_dictionary[old_key] = new_key
112
116
  new_dictionary[new_key] = value
117
+ i += 1
113
118
  end
114
119
  resources[k] = new_dictionary
115
120
  end
@@ -14,6 +14,8 @@ module CombinePDF
14
14
  #@private
15
15
  #:nodoc: all
16
16
 
17
+ protected
18
+
17
19
  # This is the Parser class.
18
20
  #
19
21
  # It takes PDF data and parses it.
@@ -157,10 +157,13 @@ module CombinePDF
157
157
  out << "/Info #{PDFOperations._object_to_pdf @info}"
158
158
  end
159
159
  out << ">>\nstartxref\n#{xref_location.to_s}\n%%EOF"
160
+ # when finished, remove the numbering system and keep only pointers
161
+ PDFOperations.remove_old_ids @objects
162
+ # output the pdf stream
160
163
  out.join("\n").force_encoding(Encoding::ASCII_8BIT)
161
164
  end
162
165
 
163
- # Seve the PDF to file.
166
+ # Save the PDF to file.
164
167
  #
165
168
  # file_name:: is a string or path object for the output.
166
169
  #
@@ -420,7 +423,7 @@ module CombinePDF
420
423
  end
421
424
  end
422
425
  # @private
423
- # run block of code on evey object (Hash)
426
+ # run block of code on evey PDF object (PDF objects are class Hash)
424
427
  def each_object(&block)
425
428
  PDFOperations._each_object(@objects, &block)
426
429
  end
@@ -484,7 +487,7 @@ module CombinePDF
484
487
  # @private
485
488
  def renumber_object_ids(start = nil)
486
489
  warn "Resetting Object Reference IDs"
487
- @set_start_id ||= start
490
+ @set_start_id = start || @set_start_id
488
491
  start = @set_start_id
489
492
  history = {}
490
493
  all_indirect_object.each do |obj|
@@ -511,7 +514,8 @@ module CombinePDF
511
514
  end
512
515
  # @private
513
516
  def all_indirect_object
514
- [].tap {|out| @objects.each {|obj| out << obj if (obj.is_a?(Hash) && obj[:is_reference_only].nil?) } }
517
+ # [].tap {|out| @objects.each {|obj| out << obj if (obj.is_a?(Hash) && obj[:is_reference_only].nil?) } }
518
+ @objects
515
519
  end
516
520
  # @private
517
521
  def sort_objects_by_id
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: combine_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev