|
|
@ -14,7 +14,7 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
/* globals assertWellFormed, calculateMD5, Catalog, error, info, isArray, |
|
|
|
/* globals assertWellFormed, calculateMD5, Catalog, Dict, error, info, isArray, |
|
|
|
isArrayBuffer, isName, isStream, isString, LegacyPromise, |
|
|
|
isArrayBuffer, isName, isStream, isString, LegacyPromise, |
|
|
|
Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer, |
|
|
|
Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer, |
|
|
|
StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef, |
|
|
|
StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef, |
|
|
@ -25,6 +25,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
var Page = (function PageClosure() { |
|
|
|
var Page = (function PageClosure() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792]; |
|
|
|
|
|
|
|
|
|
|
|
function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) { |
|
|
|
function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) { |
|
|
|
this.pdfManager = pdfManager; |
|
|
|
this.pdfManager = pdfManager; |
|
|
|
this.pageIndex = pageIndex; |
|
|
|
this.pageIndex = pageIndex; |
|
|
@ -42,20 +44,24 @@ var Page = (function PageClosure() { |
|
|
|
getPageProp: function Page_getPageProp(key) { |
|
|
|
getPageProp: function Page_getPageProp(key) { |
|
|
|
return this.pageDict.get(key); |
|
|
|
return this.pageDict.get(key); |
|
|
|
}, |
|
|
|
}, |
|
|
|
inheritPageProp: function Page_inheritPageProp(key) { |
|
|
|
|
|
|
|
|
|
|
|
getInheritedPageProp: function Page_inheritPageProp(key) { |
|
|
|
var dict = this.pageDict; |
|
|
|
var dict = this.pageDict; |
|
|
|
var obj = dict.get(key); |
|
|
|
var value = dict.get(key); |
|
|
|
while (obj === undefined) { |
|
|
|
while (value === undefined) { |
|
|
|
dict = dict.get('Parent'); |
|
|
|
dict = dict.get('Parent'); |
|
|
|
if (!dict) |
|
|
|
if (!dict) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
obj = dict.get(key); |
|
|
|
} |
|
|
|
|
|
|
|
value = dict.get(key); |
|
|
|
} |
|
|
|
} |
|
|
|
return obj; |
|
|
|
return value; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get content() { |
|
|
|
get content() { |
|
|
|
return this.getPageProp('Contents'); |
|
|
|
return this.getPageProp('Contents'); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get resources() { |
|
|
|
get resources() { |
|
|
|
var value = this.getInheritedPageProp('Resources'); |
|
|
|
var value = this.getInheritedPageProp('Resources'); |
|
|
|
// For robustness: The spec states that a \Resources entry has to be
|
|
|
|
// For robustness: The spec states that a \Resources entry has to be
|
|
|
@ -66,34 +72,41 @@ var Page = (function PageClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
return shadow(this, 'resources', value); |
|
|
|
return shadow(this, 'resources', value); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get mediaBox() { |
|
|
|
get mediaBox() { |
|
|
|
var obj = this.inheritPageProp('MediaBox'); |
|
|
|
var obj = this.getInheritedPageProp('MediaBox'); |
|
|
|
// Reset invalid media box to letter size.
|
|
|
|
// Reset invalid media box to letter size.
|
|
|
|
if (!isArray(obj) || obj.length !== 4) |
|
|
|
if (!isArray(obj) || obj.length !== 4) { |
|
|
|
obj = [0, 0, 612, 792]; |
|
|
|
obj = LETTER_SIZE_MEDIABOX; |
|
|
|
|
|
|
|
} |
|
|
|
return shadow(this, 'mediaBox', obj); |
|
|
|
return shadow(this, 'mediaBox', obj); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get view() { |
|
|
|
get view() { |
|
|
|
var mediaBox = this.mediaBox; |
|
|
|
var mediaBox = this.mediaBox; |
|
|
|
var cropBox = this.inheritPageProp('CropBox'); |
|
|
|
var cropBox = this.getInheritedPageProp('CropBox'); |
|
|
|
if (!isArray(cropBox) || cropBox.length !== 4) |
|
|
|
if (!isArray(cropBox) || cropBox.length !== 4) { |
|
|
|
return shadow(this, 'view', mediaBox); |
|
|
|
return shadow(this, 'view', mediaBox); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// From the spec, 6th ed., p.963:
|
|
|
|
// From the spec, 6th ed., p.963:
|
|
|
|
// "The crop, bleed, trim, and art boxes should not ordinarily
|
|
|
|
// "The crop, bleed, trim, and art boxes should not ordinarily
|
|
|
|
// extend beyond the boundaries of the media box. If they do, they are
|
|
|
|
// extend beyond the boundaries of the media box. If they do, they are
|
|
|
|
// effectively reduced to their intersection with the media box."
|
|
|
|
// effectively reduced to their intersection with the media box."
|
|
|
|
cropBox = Util.intersect(cropBox, mediaBox); |
|
|
|
cropBox = Util.intersect(cropBox, mediaBox); |
|
|
|
if (!cropBox) |
|
|
|
if (!cropBox) { |
|
|
|
return shadow(this, 'view', mediaBox); |
|
|
|
return shadow(this, 'view', mediaBox); |
|
|
|
|
|
|
|
} |
|
|
|
return shadow(this, 'view', cropBox); |
|
|
|
return shadow(this, 'view', cropBox); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get annotationRefs() { |
|
|
|
get annotationRefs() { |
|
|
|
return shadow(this, 'annotationRefs', this.inheritPageProp('Annots')); |
|
|
|
return shadow(this, 'annotationRefs', |
|
|
|
|
|
|
|
this.getInheritedPageProp('Annots')); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get rotate() { |
|
|
|
get rotate() { |
|
|
|
var rotate = this.inheritPageProp('Rotate') || 0; |
|
|
|
var rotate = this.getInheritedPageProp('Rotate') || 0; |
|
|
|
// Normalize rotation so it's a multiple of 90 and between 0 and 270
|
|
|
|
// Normalize rotation so it's a multiple of 90 and between 0 and 270
|
|
|
|
if (rotate % 90 !== 0) { |
|
|
|
if (rotate % 90 !== 0) { |
|
|
|
rotate = 0; |
|
|
|
rotate = 0; |
|
|
@ -106,6 +119,7 @@ var Page = (function PageClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
return shadow(this, 'rotate', rotate); |
|
|
|
return shadow(this, 'rotate', rotate); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getContentStream: function Page_getContentStream() { |
|
|
|
getContentStream: function Page_getContentStream() { |
|
|
|
var content = this.content; |
|
|
|
var content = this.content; |
|
|
|
var stream; |
|
|
|
var stream; |
|
|
@ -125,9 +139,10 @@ var Page = (function PageClosure() { |
|
|
|
} |
|
|
|
} |
|
|
|
return stream; |
|
|
|
return stream; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
loadResources: function(keys) { |
|
|
|
loadResources: function(keys) { |
|
|
|
if (!this.resourcesPromise) { |
|
|
|
if (!this.resourcesPromise) { |
|
|
|
// TODO: add async inheritPageProp and remove this.
|
|
|
|
// TODO: add async getInheritedPageProp and remove this.
|
|
|
|
this.resourcesPromise = this.pdfManager.ensure(this, 'resources'); |
|
|
|
this.resourcesPromise = this.pdfManager.ensure(this, 'resources'); |
|
|
|
} |
|
|
|
} |
|
|
|
var promise = new LegacyPromise(); |
|
|
|
var promise = new LegacyPromise(); |
|
|
@ -141,6 +156,7 @@ var Page = (function PageClosure() { |
|
|
|
}.bind(this)); |
|
|
|
}.bind(this)); |
|
|
|
return promise; |
|
|
|
return promise; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getOperatorList: function Page_getOperatorList(handler, intent) { |
|
|
|
getOperatorList: function Page_getOperatorList(handler, intent) { |
|
|
|
var self = this; |
|
|
|
var self = this; |
|
|
|
var promise = new LegacyPromise(); |
|
|
|
var promise = new LegacyPromise(); |
|
|
@ -160,7 +176,7 @@ var Page = (function PageClosure() { |
|
|
|
'Pattern', |
|
|
|
'Pattern', |
|
|
|
'Shading', |
|
|
|
'Shading', |
|
|
|
'XObject', |
|
|
|
'XObject', |
|
|
|
'Font', |
|
|
|
'Font' |
|
|
|
// ProcSet
|
|
|
|
// ProcSet
|
|
|
|
// Properties
|
|
|
|
// Properties
|
|
|
|
]); |
|
|
|
]); |
|
|
@ -208,6 +224,7 @@ var Page = (function PageClosure() { |
|
|
|
|
|
|
|
|
|
|
|
return promise; |
|
|
|
return promise; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
extractTextContent: function Page_extractTextContent() { |
|
|
|
extractTextContent: function Page_extractTextContent() { |
|
|
|
var handler = { |
|
|
|
var handler = { |
|
|
|
on: function nullHandlerOn() {}, |
|
|
|
on: function nullHandlerOn() {}, |
|
|
|