Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that saving, in the viewer, works for partially loaded documents #18254

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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