Skip to content

Commit

Permalink
Merge pull request #18254 from Snuffleupagus/force-save
Browse files Browse the repository at this point in the history
Ensure that saving, in the viewer, works for partially loaded documents
  • Loading branch information
Snuffleupagus authored Jun 16, 2024
2 parents ee94391 + f4912db commit 7b0c034
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -1109,8 +1099,6 @@ const PDFViewerApplication = {
await this.pdfScriptingManager.dispatchWillSave();

try {
this._ensureDownloadComplete();

const data = await this.pdfDocument.saveDocument();
this.downloadManager.download(
data,
Expand All @@ -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 {
Expand Down

0 comments on commit 7b0c034

Please sign in to comment.