mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Move getPage
, on the worker side, from Catalog
and into PDFDocument
instead
Addresses an existing TODO, and avoids having to pass in a `pageFactory` when creating `Catalog` instances.
This commit is contained in:
parent
51b0e60f9b
commit
fbb25ff4e2
2 changed files with 22 additions and 33 deletions
|
@ -355,6 +355,7 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||
xref: this.xref,
|
||||
isEvalSupported: evaluatorOptions.isEvalSupported,
|
||||
});
|
||||
this._pagePromises = [];
|
||||
}
|
||||
|
||||
function find(stream, needle, limit, backwards) {
|
||||
|
@ -520,21 +521,7 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||
},
|
||||
setup: function PDFDocument_setup(recoveryMode) {
|
||||
this.xref.parse(recoveryMode);
|
||||
var pageFactory = {
|
||||
createPage: (pageIndex, dict, ref, fontCache, builtInCMapCache) => {
|
||||
return new Page({
|
||||
pdfManager: this.pdfManager,
|
||||
xref: this.xref,
|
||||
pageIndex,
|
||||
pageDict: dict,
|
||||
ref,
|
||||
fontCache,
|
||||
builtInCMapCache,
|
||||
pdfFunctionFactory: this.pdfFunctionFactory,
|
||||
});
|
||||
},
|
||||
};
|
||||
this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
|
||||
this.catalog = new Catalog(this.pdfManager, this.xref);
|
||||
},
|
||||
get numPages() {
|
||||
var linearization = this.linearization;
|
||||
|
@ -599,8 +586,25 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||
return shadow(this, 'fingerprint', fileID);
|
||||
},
|
||||
|
||||
getPage: function PDFDocument_getPage(pageIndex) {
|
||||
return this.catalog.getPage(pageIndex);
|
||||
getPage(pageIndex) {
|
||||
if (this._pagePromises[pageIndex] !== undefined) {
|
||||
return this._pagePromises[pageIndex];
|
||||
}
|
||||
const catalog = this.catalog;
|
||||
|
||||
return this._pagePromises[pageIndex] =
|
||||
catalog.getPageDict(pageIndex).then(([pageDict, ref]) => {
|
||||
return new Page({
|
||||
pdfManager: this.pdfManager,
|
||||
xref: this.xref,
|
||||
pageIndex,
|
||||
pageDict,
|
||||
ref,
|
||||
fontCache: catalog.fontCache,
|
||||
builtInCMapCache: catalog.builtInCMapCache,
|
||||
pdfFunctionFactory: this.pdfFunctionFactory,
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
cleanup: function PDFDocument_cleanup() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue