combine_pdf 0.2.5 → 0.2.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: 61c4d75ddd1975e567b4b96359f852a4eb13fdf7
4
- data.tar.gz: 304f0b46cf41a96eddc46c728a20caf9ff77912c
3
+ metadata.gz: 63c084e190f8c5f47aaa3db6cd32064a7e7dcfb2
4
+ data.tar.gz: dbd7e1efe7b372abae318839eb80658913664b29
5
5
  SHA512:
6
- metadata.gz: 256814f346635778e23265a652ce800e3c951e21e647943f752b2d231ddc68c90cc6ffeb7cfacaadd34b42faff97233637752cbd68329ff064728d673c989fdf
7
- data.tar.gz: 29c90166699f5baf305398a1382e2f0db4ceb00e35391955cb5f6a30012a445fd48f3ce5e2d5154851ad1b9ae8d580f286de71ffe8b881e580b051faa1e1ec13
6
+ metadata.gz: a374e9be84a6397294a09b1fc76ae0a346ee9bce8abf1d8750742417494ecacf2b49ed843c060c13716046121d5c1ca3b570bf7fc18c828a99ce5cb857a043fc
7
+ data.tar.gz: bf343d5749131896f4fe1dc2882bd62eb0696eb20c9021048e0b1d8f15837b580a0b50a4db083e752a3e73aa5bcbc88909f78c5d46b7f5ddb1e38cb264919e17
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ***
4
4
 
5
+ Change log v.0.2.6
6
+
7
+ **fixed**: Hasan Iskandar fixed issue #30 - Output file cannot be saved from Adobe Reader with "Save As optimizes for Fast Web View" preference enabled. Thank you Hasan.
8
+
9
+ **update**: More parsing error detection; Updated the endstream EOL marker indentifier for safer indentification.
10
+
11
+ ***
12
+
5
13
  Change log v.0.2.5
6
14
 
7
15
  **feature**: circumvents an issue with 'wkhtmltopdf', where sometimes the `endobj` keyword would be missing, causing malformed PDF data. The parser will now attempt to auto-fix any `endobj` missing keywords.
@@ -65,10 +65,13 @@ module CombinePDF
65
65
  @scanner.pos = 0
66
66
  if @scanner.scan /\%PDF\-[\d\-\.]+/
67
67
  @version = @scanner.matched.scan(/[\d\.]+/)[0].to_f
68
+ @scanner.skip_until /[\n\r]+/
69
+ # @scanner.skip /[^\d]*/
68
70
  end
69
-
70
71
  @parsed = _parse_
71
72
 
73
+ raise "Unknown PDF parsing error - maleformed PDF file?" unless (@parsed.select {|i| !i.is_a?(Hash)}).empty?
74
+
72
75
  if @root_object == {}
73
76
  xref_streams = @parsed.select {|obj| obj.is_a?(Hash) && obj[:Type] == :XRef}
74
77
  xref_streams.each do |xref_dictionary|
@@ -175,8 +178,8 @@ module CombinePDF
175
178
  raise "Parsing Error: PDF file error - a stream object wasn't properly colsed using 'endstream'!" unless str
176
179
  # need to remove end of stream
177
180
  if out.last.is_a? Hash
178
- out.last[:raw_stream_content] = str[0...-10] #cuts only one EON char (\n or \r)
179
- # out.last[:raw_stream_content] = str.gsub(/[\n\r]?[\n\r]?endstream/, "")
181
+ # out.last[:raw_stream_content] = str[0...-10] #cuts only one EON char (\n or \r)
182
+ out.last[:raw_stream_content] = str.gsub(/[\n\r]?[\n\r]endstream\z/, "")
180
183
  else
181
184
  warn "Stream not attached to dictionary!"
182
185
  out << str[0...-10].force_encoding(Encoding::ASCII_8BIT)
@@ -323,7 +326,7 @@ module CombinePDF
323
326
  if @scanner.matched[-1] == 'r'
324
327
  if @scanner.skip_until(/<</)
325
328
  data = _parse_
326
- @root_object = {}
329
+ @root_object ||= {}
327
330
  @root_object[data.shift] = data.shift while data[0]
328
331
  end
329
332
  ##########
@@ -110,6 +110,8 @@ module CombinePDF
110
110
  def rebuild_catalog_and_objects
111
111
  catalog = rebuild_catalog
112
112
  @objects = []
113
+ @objects << @info
114
+ add_referenced @info
113
115
  @objects << catalog
114
116
  add_referenced catalog
115
117
  catalog
@@ -163,8 +163,10 @@ module CombinePDF
163
163
  def to_pdf options = {}
164
164
  #reset version if not specified
165
165
  @version = 1.5 if @version.to_f == 0.0
166
- #set creation date for merged file
167
- @info[:CreationDate] = Time.now.strftime "D:%Y%m%d%H%M%S%:::z'00"
166
+ #set info for merged file
167
+ @info[:ModDate] = @info[:CreationDate] = Time.now.strftime "D:%Y%m%d%H%M%S%:::z'00"
168
+ @info[:Subject] = options[:subject] if options[:subject]
169
+ @info[:Producer] = options[:producer] if options[:producer]
168
170
  #rebuild_catalog
169
171
  catalog = rebuild_catalog_and_objects
170
172
  # add ID and generation numbers to objects
@@ -193,13 +195,7 @@ module CombinePDF
193
195
  out << out.pop + "trailer"
194
196
  out << "<<\n/Root #{false || "#{catalog[:indirect_reference_id]} #{catalog[:indirect_generation_number]} R"}"
195
197
  out << "/Size #{indirect_object_count.to_s}"
196
- if @info.is_a?(Hash)
197
- PRIVATE_HASH_KEYS.each {|key| @info.delete key} # make sure the dictionary is rendered inline, without stream
198
- @info[:CreationDate] = @info[:ModDate] = Time.now.strftime "D:%Y%m%d%H%M%S%:::z'00"
199
- @info[:Subject] = options[:subject] if options[:subject]
200
- @info[:Producer] = options[:producer] if options[:producer]
201
- out << "/Info #{object_to_pdf @info}"
202
- end
198
+ out << "/Info #{@info[:indirect_reference_id]} #{@info[:indirect_generation_number]} R"
203
199
  out << ">>\nstartxref\n#{xref_location.to_s}\n%%EOF"
204
200
  # when finished, remove the numbering system and keep only pointers
205
201
  remove_old_ids
@@ -1,4 +1,4 @@
1
1
  module CombinePDF
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
4
4
 
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: 0.2.5
4
+ version: 0.2.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: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-rc4
@@ -102,10 +102,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.4.5
105
+ rubygems_version: 2.4.5.1
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: Combine, stamp and watermark PDF files in pure Ruby.
109
109
  test_files:
110
110
  - test/console
111
- has_rdoc: