combine_pdf 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/combine_pdf/parser.rb +49 -31
- data/lib/combine_pdf/version.rb +1 -1
- data/test/automated +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fced5e9fb501777c32a0c483d00c9ae0ff3875406cd6367eb8a1ac5193a5ba3
|
4
|
+
data.tar.gz: '08bdd4f49d69a25a2d83b0a28dc13d6e07c2e100f986404a516f1995f11db2b9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b55bfcb34ebc64b3fc9749dfb119bd719d873d814fa340443bf346aeab233de151c6d57f2c90cf25d50053c3880b0d3f946fa028ef353b4356e02537ef729467
|
7
|
+
data.tar.gz: e1307d1b99aa5c174b2bde19311213fcd69248ba2fcb622e1497b1981e06fd026f7493c33fc30e38861460849c25f5072644223a241e7cf9e4b1489170c93cd4
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
|
3
3
|
***
|
4
4
|
|
5
|
+
#### Change log v.1.0.10
|
6
|
+
|
7
|
+
**Fix**: Fixed an issue related to issue #131 where parsing would fail if the `xref` section appears to be misplaced within the PDF. Credit to @bharat303 (Bharat Godhani) for exposing this issue.
|
8
|
+
|
5
9
|
#### Change log v.1.0.9
|
6
10
|
|
7
|
-
**Fix**: Fixed issue #136 where the `#fix_rotation` function would rotate the page to the wrong direction. Credit to @dmkash for exposing this issue
|
11
|
+
**Fix**: Fixed issue #136 where the `#fix_rotation` function would rotate the page to the wrong direction. Credit to @dmkash for exposing this issue.
|
8
12
|
|
9
13
|
#### Change log v.1.0.8
|
10
14
|
|
data/lib/combine_pdf/parser.rb
CHANGED
@@ -80,6 +80,7 @@ module CombinePDF
|
|
80
80
|
# puts @parsed
|
81
81
|
|
82
82
|
unless (@parsed.select { |i| !i.is_a?(Hash) }).empty?
|
83
|
+
# p @parsed.select
|
83
84
|
raise ParsingError, 'Unknown PDF parsing error - malformed PDF file?'
|
84
85
|
end
|
85
86
|
|
@@ -385,17 +386,6 @@ module CombinePDF
|
|
385
386
|
out.last[:Dest] = unify_string(out.last[:Dest].to_s) if out.last[:Dest] && out.last[:Dest].is_a?(Symbol)
|
386
387
|
# puts "!!!!!!!!! Error with :indirect_reference_id\n\nObject #{out.last} :indirect_reference_id = #{out.last[:indirect_reference_id]}" unless out.last[:indirect_reference_id].is_a?(Numeric)
|
387
388
|
##########################################
|
388
|
-
## Parse a comment
|
389
|
-
##########################################
|
390
|
-
elsif str = @scanner.scan(/\%/)
|
391
|
-
# is a comment, skip until new line
|
392
|
-
loop do
|
393
|
-
# break unless @scanner.scan(/[^\d\r\n]+/)
|
394
|
-
break if @scanner.check(/([\d]+[\s]+[\d]+[\s]+obj[\s]+\<\<)|([\n\r]+)/) || @scanner.eos? # || @scanner.scan(/[^\d]+[\r\n]+/) ||
|
395
|
-
@scanner.scan(/[^\d\r\n]+/) || @scanner.pos += 1
|
396
|
-
end
|
397
|
-
# puts "AFTER COMMENT: #{@scanner.peek 8}"
|
398
|
-
##########################################
|
399
389
|
## Parse an Object Reference
|
400
390
|
##########################################
|
401
391
|
elsif @scanner.scan(/R/)
|
@@ -414,32 +404,57 @@ module CombinePDF
|
|
414
404
|
elsif @scanner.scan(/null/)
|
415
405
|
out << nil
|
416
406
|
##########################################
|
407
|
+
## Parse file trailer
|
408
|
+
##########################################
|
409
|
+
elsif @scanner.scan(/trailer/)
|
410
|
+
if @scanner.skip_until(/<</)
|
411
|
+
data = _parse_
|
412
|
+
(@root_object ||= {}).clear
|
413
|
+
@root_object[data.shift] = data.shift while data[0]
|
414
|
+
end
|
415
|
+
##########################################
|
417
416
|
## XREF - check for encryption... anything else?
|
418
417
|
##########################################
|
419
|
-
elsif @scanner.scan(/
|
420
|
-
|
421
|
-
|
422
|
-
@scanner.
|
423
|
-
|
424
|
-
|
425
|
-
if @scanner.skip_until(/<</)
|
426
|
-
data = _parse_
|
427
|
-
(@root_object ||= {}).clear
|
428
|
-
@root_object[data.shift] = data.shift while data[0]
|
429
|
-
end
|
430
|
-
##########
|
431
|
-
## skip untill end of segment, maked by %%EOF
|
432
|
-
@scanner.skip_until(/\%\%EOF/)
|
433
|
-
##########
|
434
|
-
## If this was the last valid segment, ignore any trailing garbage
|
435
|
-
## (issue #49 resolution)
|
436
|
-
break unless @scanner.exist?(/\%\%EOF/)
|
437
|
-
|
418
|
+
elsif @scanner.scan(/xref/)
|
419
|
+
# skip first xref line
|
420
|
+
@scanner.scan(/[\s]+[\d]+[\s]+[\d]+[\s]+/)
|
421
|
+
while @scanner.scan(/[\d]+[\s][\d]+[\s]+[nf][\s]+/)
|
422
|
+
# skip all xref lines
|
423
|
+
nil
|
438
424
|
end
|
439
|
-
|
425
|
+
##########################################
|
426
|
+
## XREF location can be ignored
|
427
|
+
##########################################
|
428
|
+
elsif @scanner.scan(/startxref/)
|
429
|
+
@scanner.scan(/[\s]+[\d]+[\s]+/)
|
430
|
+
##########################################
|
431
|
+
## Skip Whitespace
|
432
|
+
##########################################
|
440
433
|
elsif @scanner.scan(/[\s]+/)
|
441
434
|
# Generally, do nothing
|
442
435
|
nil
|
436
|
+
##########################################
|
437
|
+
## EOF?
|
438
|
+
##########################################
|
439
|
+
elsif @scanner.scan(/\%\%EOF/)
|
440
|
+
##########
|
441
|
+
## If this was the last valid segment, ignore any trailing garbage
|
442
|
+
## (issue #49 resolution)
|
443
|
+
break unless @scanner.exist?(/\%\%EOF/)
|
444
|
+
##########################################
|
445
|
+
## Parse a comment
|
446
|
+
##########################################
|
447
|
+
elsif str = @scanner.scan(/\%/)
|
448
|
+
# is a comment, skip until new line
|
449
|
+
loop do
|
450
|
+
# break unless @scanner.scan(/[^\d\r\n]+/)
|
451
|
+
break if @scanner.check(/([\d]+[\s]+[\d]+[\s]+obj[\s]+\<\<)|([\n\r]+)/) || @scanner.eos? # || @scanner.scan(/[^\d]+[\r\n]+/) ||
|
452
|
+
@scanner.scan(/[^\d\r\n]+/) || @scanner.pos += 1
|
453
|
+
end
|
454
|
+
# puts "AFTER COMMENT: #{@scanner.peek 8}"
|
455
|
+
##########################################
|
456
|
+
## Fix wkhtmltopdf - missing 'endobj' keywords
|
457
|
+
##########################################
|
443
458
|
elsif @scanner.scan(/obj[\s]*/)
|
444
459
|
# Fix wkhtmltopdf PDF authoring issue - missing 'endobj' keywords
|
445
460
|
unless fresh || (out[-4].nil? || out[-4].is_a?(Hash))
|
@@ -460,6 +475,9 @@ module CombinePDF
|
|
460
475
|
out << keep.pop
|
461
476
|
end
|
462
477
|
fresh = false
|
478
|
+
##########################################
|
479
|
+
## Unknown, warn and advance
|
480
|
+
##########################################
|
463
481
|
else
|
464
482
|
# always advance
|
465
483
|
# warn "Advancing for unknown reason... #{@scanner.string[@scanner.pos - 4, 8]} ... #{@scanner.peek(4)}" unless @scanner.peek(1) =~ /[\s\n]/
|
data/lib/combine_pdf/version.rb
CHANGED
data/test/automated
CHANGED
@@ -95,6 +95,7 @@ pdf.save('07_named destinations_numbered.pdf')
|
|
95
95
|
CombinePDF.load("./Ruby/test\ pdfs/Scribus-unknown_err.pdf").save '08_1-unknown-err-empty-str.pdf'
|
96
96
|
CombinePDF.load("./Ruby/test\ pdfs/Scribus-unknown_err2.pdf").save '08_2-unknown-err-empty-str.pdf'
|
97
97
|
CombinePDF.load("./Ruby/test\ pdfs/Scribus-unknown_err3.pdf").save '08_3-unknown-err-empty-str.pdf'
|
98
|
+
CombinePDF.load("./Ruby/test\ pdfs/xref_in_middle.pdf").save '08_4-xref-in-middle.pdf'
|
98
99
|
|
99
100
|
CombinePDF.load("/Users/2Be/Ruby/test\ pdfs/nil_object.pdf").save('09_nil_in_parsed_array.pdf')
|
100
101
|
|
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.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boaz Segev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-rc4
|