1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Create a fallback annotation id for entries in Annots dictionaries that are not indirect objects (issue 7569)

According to the PDF specification, see http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#page=86, entries in `Annots` dictionaries should be indirect objects, but obviously there're PDF generators that ignore this.

Fixes 7569.
This commit is contained in:
Jonas Jenwald 2016-08-26 16:01:25 +02:00
parent 0e20d44fef
commit 78889646c8
3 changed files with 110 additions and 33 deletions

View file

@ -49,6 +49,7 @@ var warn = sharedUtil.warn;
var Dict = corePrimitives.Dict;
var isDict = corePrimitives.isDict;
var isName = corePrimitives.isName;
var isRef = corePrimitives.isRef;
var Stream = coreStream.Stream;
var ColorSpace = coreColorSpace.ColorSpace;
var ObjectLoader = coreObj.ObjectLoader;
@ -66,11 +67,14 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
* @param {Object} ref
* @returns {Annotation}
*/
create: function AnnotationFactory_create(xref, ref) {
create: function AnnotationFactory_create(xref, ref,
uniquePrefix, idCounters) {
var dict = xref.fetchIfRef(ref);
if (!isDict(dict)) {
return;
}
var id = isRef(ref) ? ref.toString() :
'annot_' + (uniquePrefix || '') + (++idCounters.obj);
// Determine the annotation's subtype.
var subtype = dict.get('Subtype');
@ -80,8 +84,9 @@ AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
var parameters = {
xref: xref,
dict: dict,
ref: ref,
ref: isRef(ref) ? ref : null,
subtype: subtype,
id: id,
};
switch (subtype) {
@ -185,7 +190,7 @@ var Annotation = (function AnnotationClosure() {
// Expose public properties using a data object.
this.data = {};
this.data.id = params.ref.toString();
this.data.id = params.id;
this.data.subtype = params.subtype;
this.data.annotationFlags = this.flags;
this.data.rect = this.rectangle;

View file

@ -76,6 +76,7 @@ var Page = (function PageClosure() {
this.xref = xref;
this.ref = ref;
this.fontCache = fontCache;
this.uniquePrefix = 'p' + this.pageIndex + '_';
this.idCounters = {
obj: 0
};
@ -223,7 +224,7 @@ var Page = (function PageClosure() {
var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
handler, this.pageIndex,
'p' + this.pageIndex + '_',
this.uniquePrefix,
this.idCounters,
this.fontCache,
this.evaluatorOptions);
@ -290,7 +291,7 @@ var Page = (function PageClosure() {
var contentStream = data[0];
var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
handler, self.pageIndex,
'p' + self.pageIndex + '_',
self.uniquePrefix,
self.idCounters,
self.fontCache,
self.evaluatorOptions);
@ -325,7 +326,9 @@ var Page = (function PageClosure() {
var annotationFactory = new AnnotationFactory();
for (var i = 0, n = annotationRefs.length; i < n; ++i) {
var annotationRef = annotationRefs[i];
var annotation = annotationFactory.create(this.xref, annotationRef);
var annotation = annotationFactory.create(this.xref, annotationRef,
this.uniquePrefix,
this.idCounters);
if (annotation) {
annotations.push(annotation);
}