Skip to content

Commit

Permalink
Separate page label extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Jul 4, 2024
1 parent 7e5dddb commit 9a77b02
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/module/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export class Module {
}

async getPageLabels() {
return getPageLabels(this._pdfDocument, this._structuredCharsProvider);
if (this._pageLabelsPromise) {
await this._pageLabelsPromise;
return this._pageLabels;
}
let resolvePageLabelsPromise;
this._pageLabelsPromise = new Promise((resolve) => {
resolvePageLabelsPromise = resolve;
});
this._pageLabels = await getPageLabels(this._pdfDocument, this._structuredCharsProvider);
resolvePageLabelsPromise();
return this._pageLabels;
}
}
13 changes: 13 additions & 0 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,19 @@ class WorkerMessageHandler {
return pageData;
});

handler.on("GetPageLabels2", async function (data) {
let task = new WorkerTask('GetPageLabels2: ');
startWorkerTask(task);
let pageLabels;
try {
pageLabels = await pdfManager.pdfDocument.module.getPageLabels(data);
} catch (e) {
console.log(e);
}
finishWorkerTask(task);
return pageLabels;
});

handler.on("GetOutline2", async function (data) {
let task = new WorkerTask('GetOutline2');
startWorkerTask(task);
Expand Down
4 changes: 4 additions & 0 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,10 @@ class PDFDocumentProxy {
return this._transport.messageHandler.sendWithPromise("GetProcessedData", data);
}

getPageLabels2(data) {
return this._transport.messageHandler.sendWithPromise("GetPageLabels2", data);
}

getOutline2(data) {
return this._transport.messageHandler.sendWithPromise("GetOutline2", data);
}
Expand Down

0 comments on commit 9a77b02

Please sign in to comment.