diff --git a/base/core/core.js b/base/core/core.js index ea69f9d9..138828d5 100755 --- a/base/core/core.js +++ b/base/core/core.js @@ -138,7 +138,6 @@ var Page = (function PageClosure() { return promise; }, getOperatorList: function Page_getOperatorList(handler) { - var self = this; var promise = new Promise(); function reject(e) { @@ -148,8 +147,7 @@ var Page = (function PageClosure() { var pageListPromise = new Promise(); var pdfManager = this.pdfManager; - var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', - []); + var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []); var resourcesPromise = this.loadResources([ 'ExtGState', 'ColorSpace', @@ -166,35 +164,31 @@ var Page = (function PageClosure() { this.pageIndex, 'p' + this.pageIndex + '_', this.idCounters, this.fontCache); - var dataPromises = Promise.all( - [contentStreamPromise, resourcesPromise], reject); - dataPromises.then(function(data) { + Promise.all([contentStreamPromise, resourcesPromise]).then(function(data) { var contentStream = data[0]; - - - var opList = new OperatorList(handler, self.pageIndex); - try { - handler.send('StartRenderPage', { - transparency: partialEvaluator.hasBlendModes(self.resources), - pageIndex: self.pageIndex - }); - partialEvaluator.getOperatorList(contentStream, self.resources, opList); - pageListPromise.resolve(opList); - } - catch(e) { - pageListPromise.reject(e); - } - }); + try { + var opList = new OperatorList(handler, this.pageIndex); + partialEvaluator.getOperatorList(contentStream, this.resources, opList); + pageListPromise.resolve(opList); + + handler.send('StartRenderPage', { + transparency: partialEvaluator.hasBlendModes(this.resources), + pageIndex: this.pageIndex + }); + } catch (ex) { + reject(ex); + } + }.bind(this), reject); var annotationsPromise = pdfManager.ensure(this, 'annotations'); - Promise.all([pageListPromise, annotationsPromise]).then(function(datas) { - var pageOpList = datas[0]; - var annotations = datas[1]; + Promise.all([pageListPromise, annotationsPromise]).then(function(data) { + var pageOpList = data[0]; + var annotations = data[1]; if (annotations.length === 0) { pageOpList.flush(true); promise.resolve(pageOpList); - return; + return promise; } var annotationsReadyPromise = Annotation.appendToOperatorList( diff --git a/base/display/metadata.js b/base/display/metadata.js index 6b1c3c26..ecc85531 100755 --- a/base/display/metadata.js +++ b/base/display/metadata.js @@ -45,19 +45,18 @@ var Metadata = (PDFJS.Metadata = (function MetadataClosure() { } function Metadata(meta) { - if (typeof meta === 'string') { + this.metadata = {}; + if (typeof meta === 'string') { // Ghostscript produces invalid metadata meta = fixMetadata(meta); - - var parser = new DOMParser(); - meta = parser.parseFromString(meta, 'application/xml'); - } else if (!(meta instanceof Document)) { - error('Metadata: Invalid metadata object'); - } - - this.metaDocument = meta; - this.metadata = {}; - this.parse(); + meta = meta.trim(); + if (meta.startsWith('<') && meta.endsWith('>')) { + var parser = new DOMParser(); + meta = parser.parseFromString(meta, 'application/xml'); + this.metaDocument = meta; + this.parse(); + } + } } Metadata.prototype = { diff --git a/base/shared/util.js b/base/shared/util.js index c178abe8..310e4ea9 100755 --- a/base/shared/util.js +++ b/base/shared/util.js @@ -197,8 +197,8 @@ function error(msg) { } else { //log('Error: ' + msg); } - //log(backtrace()); - //PDFJS.LogManager.notify('error', msg); + // log(backtrace()); + PDFJS.LogManager.notify('error', msg); throw new Error(msg); } diff --git a/package.json b/package.json index e7a6ae5f..60cf682f 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "test:jest": "jest --config ./jest.config.json", "test": "jest --config ./jest.config.json && npm run parse-r && npm run parse-fd", "test:forms": "cd ./test && sh p2j.forms.sh", - "test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 4 fail exception with stack trace\" ", + "test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 5 fail exception with stack trace\" ", "parse": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form", "parse-s": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s", "parse-t": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t", @@ -48,7 +48,7 @@ "parse-tb": "./bin/pdf2json.js -f ./test/pdf/misc/i242_testingWithTable.pdf -o ./test/target/misc", "parse-tc": "./bin/pdf2json.js -f ./test/pdf/misc/i293_pdfpac.pdf -o ./test/target/misc", "parse-rectFix": "./bin/pdf2json.js -f ./test/pdf/misc/pr298_rect_fix_from_upstream.pdf -o ./test/target/misc", - "parse-e": "./bin/pdf2json.js -f ./test/pdf/misc/i43_encrypted.pdf -o ./test/target/misc", + "parse-e": "./bin/pdf2json.js -f ./test/pdf/misc/i373_err_broken.pdf -o ./test/target/misc", "build:rollup": "rollup -c ./rollup.config.js", "build:bundle-pdfjs-base": "node rollup/bundle-pdfjs-base.js", "build": "npm run build:bundle-pdfjs-base && npm run build:rollup", diff --git a/test/pdf/misc/i373_err_broken.pdf b/test/pdf/misc/i373_err_broken.pdf new file mode 100644 index 00000000..e9a6da3f Binary files /dev/null and b/test/pdf/misc/i373_err_broken.pdf differ