Merge pull request #862 from notmasteryet/issue-828

Fallback to object indexing when reading of xref fails (#828)
This commit is contained in:
Artur Adib 2011-12-05 09:06:53 -08:00
commit e44521eae3

View File

@ -518,20 +518,29 @@ var XRef = (function xRefXRef() {
readXRef: function readXref(startXRef) { readXRef: function readXref(startXRef) {
var stream = this.stream; var stream = this.stream;
stream.pos = startXRef; stream.pos = startXRef;
var parser = new Parser(new Lexer(stream), true);
var obj = parser.getObj(); try {
// parse an old-style xref table var parser = new Parser(new Lexer(stream), true);
if (isCmd(obj, 'xref')) var obj = parser.getObj();
return this.readXRefTable(parser);
// parse an xref stream // parse an old-style xref table
if (isInt(obj)) { if (isCmd(obj, 'xref'))
if (!isInt(parser.getObj()) || return this.readXRefTable(parser);
!isCmd(parser.getObj(), 'obj') ||
!isStream(obj = parser.getObj())) { // parse an xref stream
error('Invalid XRef stream'); if (isInt(obj)) {
if (!isInt(parser.getObj()) ||
!isCmd(parser.getObj(), 'obj') ||
!isStream(obj = parser.getObj())) {
error('Invalid XRef stream');
}
return this.readXRefStream(obj);
} }
return this.readXRefStream(obj); } catch (e) {
log('Reading of the xref table/stream failed: ' + e);
} }
warn('Indexing all PDF objects');
return this.indexObjects(); return this.indexObjects();
}, },
getEntry: function xRefGetEntry(i) { getEntry: function xRefGetEntry(i) {