From 7c5e9cf8be1c833ecaafbe963959755a53b6556e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 15 Jun 2024 17:39:59 +0200 Subject: [PATCH] Ensure that saving, in the viewer, works for partially loaded documents Currently saving a modified PDF document may fail *intermittently*, if it's triggered before the entire document has been downloaded. When saving was originally added we only supported forms, and such PDF documents are usually small/simple enough for this issue to be difficult to trigger. However, with editing-support now available as well it's possible to modify much larger documents and this issue thus becomes easier to trigger. One way to reproduce this issue *consistently* is to: - Open http://localhost:8888/web/viewer.html?file=/test/pdfs/pdf.pdf#disableHistory=true&disableStream=true&disableAutoFetch=true - Add an annotation on the first page, it doesn't matter what kind. - Save the document. - Open the resulting document, and notice that with the `master` branch the annotation is missing. --- web/app.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/web/app.js b/web/app.js index 927d7143e..d8dd9e953 100644 --- a/web/app.js +++ b/web/app.js @@ -1109,8 +1109,6 @@ const PDFViewerApplication = { await this.pdfScriptingManager.dispatchWillSave(); try { - this._ensureDownloadComplete(); - const data = await this.pdfDocument.saveDocument(); this.downloadManager.download( data, @@ -1119,8 +1117,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 {