From d3005603e18148ea6e2f9bc9ce808ccbfd6ba69e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 4 Aug 2022 12:24:14 +0200 Subject: [PATCH] Move the `saveDocument` method, within the `PDFDocumentProxy`/`WorkerTransport` classes To improve discoverability, since these methods are very closely related, move `saveDocument` to just after `getData` instead. --- src/display/api.js | 62 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/display/api.js b/src/display/api.js index 0d2943669..678b4a92a 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -973,12 +973,29 @@ class PDFDocumentProxy { /** * @returns {Promise} A promise that is resolved with a - * {Uint8Array} that has the raw data from the PDF. + * {Uint8Array} containing the raw data of the PDF document. */ getData() { return this._transport.getData(); } + /** + * @returns {Promise} A promise that is resolved with a + * {Uint8Array} containing the full data of the saved document. + */ + saveDocument() { + if ( + (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && + this._transport.annotationStorage.size <= 0 + ) { + deprecated( + "saveDocument called while `annotationStorage` is empty, " + + "please use the getData-method instead." + ); + } + return this._transport.saveDocument(); + } + /** * @returns {Promise<{ length: number }>} A promise that is resolved when the * document's data is loaded. It is resolved with an {Object} that contains @@ -1026,23 +1043,6 @@ class PDFDocumentProxy { return this._transport.loadingTask; } - /** - * @returns {Promise} A promise that is resolved with a - * {Uint8Array} containing the full data of the saved document. - */ - saveDocument() { - if ( - (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && - this._transport.annotationStorage.size <= 0 - ) { - deprecated( - "saveDocument called while `annotationStorage` is empty, " + - "please use the getData-method instead." - ); - } - return this._transport.saveDocument(); - } - /** * @returns {Promise> | null>} A promise that is * resolved with an {Object} containing /AcroForm field data for the JS @@ -2911,6 +2911,19 @@ class WorkerTransport { return this.messageHandler.sendWithPromise("GetData", null); } + saveDocument() { + return this.messageHandler + .sendWithPromise("SaveDocument", { + isPureXfa: !!this._htmlForXfa, + numPages: this._numPages, + annotationStorage: this.annotationStorage.serializable, + filename: this._fullReader?.filename ?? null, + }) + .finally(() => { + this.annotationStorage.resetModified(); + }); + } + getPage(pageNumber) { if ( !Number.isInteger(pageNumber) || @@ -2971,19 +2984,6 @@ class WorkerTransport { }); } - saveDocument() { - return this.messageHandler - .sendWithPromise("SaveDocument", { - isPureXfa: !!this._htmlForXfa, - numPages: this._numPages, - annotationStorage: this.annotationStorage.serializable, - filename: this._fullReader?.filename ?? null, - }) - .finally(() => { - this.annotationStorage.resetModified(); - }); - } - getFieldObjects() { return (this._getFieldObjectsPromise ||= this.messageHandler.sendWithPromise("GetFieldObjects", null));