1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18254 from Snuffleupagus/force-save

Ensure that saving, in the viewer, works for partially loaded documents
This commit is contained in:
Jonas Jenwald 2024-06-16 17:26:26 +02:00 committed by GitHub
commit 7b0c0347d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1073,22 +1073,12 @@ const PDFViewerApplication = {
);
},
/**
* @private
*/
_ensureDownloadComplete() {
if (this.pdfDocument && this.downloadComplete) {
return;
}
throw new Error("PDF document not downloaded.");
},
async download(options = {}) {
let data;
try {
this._ensureDownloadComplete();
data = await this.pdfDocument.getData();
if (this.downloadComplete) {
data = await this.pdfDocument.getData();
}
} catch {
// When the PDF document isn't ready, or the PDF file is still
// downloading, simply download using the URL.
@ -1109,8 +1099,6 @@ const PDFViewerApplication = {
await this.pdfScriptingManager.dispatchWillSave();
try {
this._ensureDownloadComplete();
const data = await this.pdfDocument.saveDocument();
this.downloadManager.download(
data,
@ -1119,8 +1107,7 @@ const PDFViewerApplication = {
options
);
} catch (reason) {
// When the PDF document isn't ready, or the PDF file is still
// downloading, simply fallback to a "regular" download.
// When the PDF document isn't ready, fallback to a "regular" download.
console.error(`Error when saving the document: ${reason.message}`);
await this.download(options);
} finally {