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:
commit
7b0c0347d0
1 changed files with 4 additions and 17 deletions
21
web/app.js
21
web/app.js
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue