From 0f7f80ee6ea7ad309492a2c65bb2dedf491beab2 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 2 Dec 2011 15:31:29 -0600 Subject: [PATCH 1/2] If readXRefStream or readXRefTable fails, fallback to object indexing (#828) --- src/obj.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/obj.js b/src/obj.js index 7aebb732a..9544bea60 100644 --- a/src/obj.js +++ b/src/obj.js @@ -518,20 +518,25 @@ var XRef = (function xRefXRef() { readXRef: function readXref(startXRef) { var stream = this.stream; stream.pos = startXRef; - var parser = new Parser(new Lexer(stream), true); - var obj = parser.getObj(); - // parse an old-style xref table - if (isCmd(obj, 'xref')) - return this.readXRefTable(parser); - // parse an xref stream - if (isInt(obj)) { - if (!isInt(parser.getObj()) || - !isCmd(parser.getObj(), 'obj') || - !isStream(obj = parser.getObj())) { - error('Invalid XRef stream'); + try { + var parser = new Parser(new Lexer(stream), true); + var obj = parser.getObj(); + // parse an old-style xref table + if (isCmd(obj, 'xref')) + return this.readXRefTable(parser); + // parse an 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(); }, getEntry: function xRefGetEntry(i) { From 01a96fdddf6f979b47fd04ad431e0fdf224478b8 Mon Sep 17 00:00:00 2001 From: notmasteryet Date: Fri, 2 Dec 2011 15:35:18 -0600 Subject: [PATCH 2/2] Fixing lint errors; extra empty lines --- src/obj.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/obj.js b/src/obj.js index 9544bea60..474b54336 100644 --- a/src/obj.js +++ b/src/obj.js @@ -518,12 +518,15 @@ var XRef = (function xRefXRef() { readXRef: function readXref(startXRef) { var stream = this.stream; stream.pos = startXRef; + try { var parser = new Parser(new Lexer(stream), true); var obj = parser.getObj(); + // parse an old-style xref table if (isCmd(obj, 'xref')) return this.readXRefTable(parser); + // parse an xref stream if (isInt(obj)) { if (!isInt(parser.getObj()) || @@ -533,9 +536,10 @@ var XRef = (function xRefXRef() { } return this.readXRefStream(obj); } - } catch(e) { + } catch (e) { log('Reading of the xref table/stream failed: ' + e); } + warn('Indexing all PDF objects'); return this.indexObjects(); },