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.
This commit is contained in:
Jonas Jenwald 2022-08-04 12:24:14 +02:00
parent 3f8b5449e8
commit d3005603e1

View File

@ -973,12 +973,29 @@ class PDFDocumentProxy {
/**
* @returns {Promise<Uint8Array>} 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<Uint8Array>} 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<Uint8Array>} 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<Object<string, Array<Object>> | 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));