mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 22:58:07 +02:00
[api-minor] Attempt to support fetching the raw data of the PDF document from the PDFDocumentLoadingTask
-instance (issue 15085)
The new API-functionality will allow a PDF document to be downloaded in the viewer e.g. while the PasswordPrompt is open, or in cases when document initialization failed. Normally the raw data of the PDF document would be accessed via the `PDFDocumentProxy.prototype.getData` method, however in these cases the `PDFDocumentProxy`-instance isn't available.
This commit is contained in:
parent
d1d88cc09e
commit
9e8d4e4d46
3 changed files with 92 additions and 30 deletions
|
@ -629,39 +629,48 @@ const isValidExplicitDest = _isValidExplicitDest.bind(
|
|||
class PDFDocumentLoadingTask {
|
||||
static #docId = 0;
|
||||
|
||||
constructor() {
|
||||
this._capability = Promise.withResolvers();
|
||||
this._transport = null;
|
||||
this._worker = null;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_capability = Promise.withResolvers();
|
||||
|
||||
/**
|
||||
* Unique identifier for the document loading task.
|
||||
* @type {string}
|
||||
*/
|
||||
this.docId = `d${PDFDocumentLoadingTask.#docId++}`;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_transport = null;
|
||||
|
||||
/**
|
||||
* Whether the loading task is destroyed or not.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.destroyed = false;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_worker = null;
|
||||
|
||||
/**
|
||||
* Callback to request a password if a wrong or no password was provided.
|
||||
* The callback receives two parameters: a function that should be called
|
||||
* with the new password, and a reason (see {@link PasswordResponses}).
|
||||
* @type {function}
|
||||
*/
|
||||
this.onPassword = null;
|
||||
/**
|
||||
* Unique identifier for the document loading task.
|
||||
* @type {string}
|
||||
*/
|
||||
docId = `d${PDFDocumentLoadingTask.#docId++}`;
|
||||
|
||||
/**
|
||||
* Callback to be able to monitor the loading progress of the PDF file
|
||||
* (necessary to implement e.g. a loading bar).
|
||||
* The callback receives an {@link OnProgressParameters} argument.
|
||||
* @type {function}
|
||||
*/
|
||||
this.onProgress = null;
|
||||
}
|
||||
/**
|
||||
* Whether the loading task is destroyed or not.
|
||||
* @type {boolean}
|
||||
*/
|
||||
destroyed = false;
|
||||
|
||||
/**
|
||||
* Callback to request a password if a wrong or no password was provided.
|
||||
* The callback receives two parameters: a function that should be called
|
||||
* with the new password, and a reason (see {@link PasswordResponses}).
|
||||
* @type {function}
|
||||
*/
|
||||
onPassword = null;
|
||||
|
||||
/**
|
||||
* Callback to be able to monitor the loading progress of the PDF file
|
||||
* (necessary to implement e.g. a loading bar).
|
||||
* The callback receives an {@link OnProgressParameters} argument.
|
||||
* @type {function}
|
||||
*/
|
||||
onProgress = null;
|
||||
|
||||
/**
|
||||
* Promise for document loading task completion.
|
||||
|
@ -699,6 +708,16 @@ class PDFDocumentLoadingTask {
|
|||
this._worker?.destroy();
|
||||
this._worker = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to fetch the raw data of the PDF document, when e.g.
|
||||
* - An exception was thrown during document initialization.
|
||||
* - An `onPassword` callback is delaying initialization.
|
||||
* @returns {Promise<Uint8Array>}
|
||||
*/
|
||||
async getData() {
|
||||
return this._transport.getData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue