|
|
@ -364,9 +364,8 @@ var XRef = (function XRefClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Sanity check: as per spec, first object must have these properties
|
|
|
|
// Sanity check: as per spec, first object must be free
|
|
|
|
if (this.entries[0] && |
|
|
|
if (this.entries[0] && !this.entries[0].free) |
|
|
|
!(this.entries[0].gen === 65535 && this.entries[0].free)) |
|
|
|
|
|
|
|
error('Invalid XRef table: unexpected first object'); |
|
|
|
error('Invalid XRef table: unexpected first object'); |
|
|
|
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
// Sanity check
|
|
|
@ -525,7 +524,7 @@ var XRef = (function XRefClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
// reading XRef streams
|
|
|
|
// reading XRef streams
|
|
|
|
for (var i = 0, ii = xrefStms.length; i < ii; ++i) { |
|
|
|
for (var i = 0, ii = xrefStms.length; i < ii; ++i) { |
|
|
|
this.readXRef(xrefStms[i]); |
|
|
|
this.readXRef(xrefStms[i], true); |
|
|
|
} |
|
|
|
} |
|
|
|
// finding main trailer
|
|
|
|
// finding main trailer
|
|
|
|
var dict; |
|
|
|
var dict; |
|
|
@ -548,7 +547,7 @@ var XRef = (function XRefClosure() { |
|
|
|
// nothing helps
|
|
|
|
// nothing helps
|
|
|
|
error('Invalid PDF structure'); |
|
|
|
error('Invalid PDF structure'); |
|
|
|
}, |
|
|
|
}, |
|
|
|
readXRef: function XRef_readXRef(startXRef) { |
|
|
|
readXRef: function XRef_readXRef(startXRef, recoveryMode) { |
|
|
|
var stream = this.stream; |
|
|
|
var stream = this.stream; |
|
|
|
stream.pos = startXRef; |
|
|
|
stream.pos = startXRef; |
|
|
|
|
|
|
|
|
|
|
@ -581,16 +580,18 @@ var XRef = (function XRefClosure() { |
|
|
|
error('Invalid XRef stream'); |
|
|
|
error('Invalid XRef stream'); |
|
|
|
} |
|
|
|
} |
|
|
|
dict = this.readXRefStream(obj); |
|
|
|
dict = this.readXRefStream(obj); |
|
|
|
|
|
|
|
if (!dict) |
|
|
|
|
|
|
|
error('Failed to read XRef stream'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Recursively get previous dictionary, if any
|
|
|
|
// Recursively get previous dictionary, if any
|
|
|
|
obj = dict.get('Prev'); |
|
|
|
obj = dict.get('Prev'); |
|
|
|
if (isInt(obj)) |
|
|
|
if (isInt(obj)) |
|
|
|
this.readXRef(obj); |
|
|
|
this.readXRef(obj, recoveryMode); |
|
|
|
else if (isRef(obj)) { |
|
|
|
else if (isRef(obj)) { |
|
|
|
// The spec says Prev must not be a reference, i.e. "/Prev NNN"
|
|
|
|
// The spec says Prev must not be a reference, i.e. "/Prev NNN"
|
|
|
|
// This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
|
|
|
|
// This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
|
|
|
|
this.readXRef(obj.num); |
|
|
|
this.readXRef(obj.num, recoveryMode); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return dict; |
|
|
|
return dict; |
|
|
@ -598,6 +599,9 @@ var XRef = (function XRefClosure() { |
|
|
|
log('(while reading XRef): ' + e); |
|
|
|
log('(while reading XRef): ' + e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (recoveryMode) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
warn('Indexing all PDF objects'); |
|
|
|
warn('Indexing all PDF objects'); |
|
|
|
return this.indexObjects(); |
|
|
|
return this.indexObjects(); |
|
|
|
}, |
|
|
|
}, |
|
|
|