Skip to content

Build your personal knowledge base with Trilium Notes

fix(pdf): flush pending edits before download, drop dead iframe handler

Elian Dorand794abd55df8
diff --git a/apps/client/src/widgets/type_widgets/file/Pdf.tsx b/apps/client/src/widgets/type_widgets/file/Pdf.tsx
index 06b7a5fdcc..e6d98ad084 100644
--- a/apps/client/src/widgets/type_widgets/file/Pdf.tsx
+++ b/apps/client/src/widgets/type_widgets/file/Pdf.tsx
@@ -188,9 +188,14 @@ export default function PdfPreview({ note, blob, componentId, noteContext }: {
};
}, [ note, historyConfig, componentId, blob, noteContext, isReadOnly, spacedUpdate ]);
- useTriliumEvent("customDownload", ({ ntxId }) => {
+ useTriliumEvent("customDownload", async ({ ntxId }) => {
if (ntxId !== noteContext.ntxId) return;
+ // Flush any pending in-viewer edits (e.g. annotations) to the server before
+ // downloading, so the file reflects the latest state and not just the last
+ // debounced auto-save. No-op for read-only PDFs, which have nothing to save.
+ await spacedUpdate.updateNowIfNecessary();
+
const url = `${open.getUrlForDownload(`api/notes/${note.noteId}/download`)}?${Date.now()}`;
open.download(url);
});
diff --git a/packages/pdfjs-viewer/src/custom.ts b/packages/pdfjs-viewer/src/custom.ts
index 91b46f9de2..d0dbc25cab 100644
--- a/packages/pdfjs-viewer/src/custom.ts
+++ b/packages/pdfjs-viewer/src/custom.ts
@@ -40,7 +40,6 @@ async function main() {
if (isEditable) {
app.eventBus.on("documentloaded", () => {
manageSave();
- manageDownload();
extractAndSendToc();
setupScrollToHeading();
setupActiveHeadingTracking();
@@ -156,17 +155,6 @@ function manageSave() {
});
}
-function manageDownload() {
- window.addEventListener("message", event => {
- if (event.origin !== window.location.origin) return;
-
- if (event.data?.type === "trilium-request-download") {
- const app = window.PDFViewerApplication;
- app.eventBus.dispatch("download", { source: window });
- }
- });
-}
-
function manageParentCommands() {
window.addEventListener("message", event => {
if (event.origin !== window.location.origin) return;