Merge pull request #3376 from yurydelendik/bad-pdfs

Misc fixes for corrupted PDFs
This commit is contained in:
Brendan Dahl 2013-06-27 15:33:06 -07:00
commit f06dadab3b
5 changed files with 71 additions and 7 deletions

View file

@ -266,6 +266,18 @@ var Catalog = (function CatalogClosure() {
return shadow(this, 'toplevelPagesDict', pagesObj);
},
get documentOutline() {
var obj = null;
try {
obj = this.readDocumentOutline();
} catch (ex) {
if (ex instanceof MissingDataException) {
throw ex;
}
warn('Unable to read document outline');
}
return shadow(this, 'documentOutline', obj);
},
readDocumentOutline: function Catalog_readDocumentOutline() {
var xref = this.xref;
var obj = this.catDict.get('Outlines');
var root = { items: [] };
@ -316,8 +328,7 @@ var Catalog = (function CatalogClosure() {
}
}
}
obj = root.items.length > 0 ? root.items : null;
return shadow(this, 'documentOutline', obj);
return root.items.length > 0 ? root.items : null;
},
get numPages() {
var obj = this.toplevelPagesDict.get('Count');
@ -598,6 +609,12 @@ var XRef = (function XRefClosure() {
delete tableState.entryCount;
}
// Per issue 3248: hp scanners generate bad XRef
if (first === 1 && this.entries[1] && this.entries[1].free) {
// shifting the entries
this.entries.shift();
}
// Sanity check: as per spec, first object must be free
if (this.entries[0] && !this.entries[0].free)
error('Invalid XRef table: unexpected first object');