diff --git a/src/lib/components/viewer/PDF.svelte b/src/lib/components/viewer/PDF.svelte index ba0bab7fd..3ac5e2ac8 100644 --- a/src/lib/components/viewer/PDF.svelte +++ b/src/lib/components/viewer/PDF.svelte @@ -19,9 +19,11 @@ import { getCurrentPage, getDocument, + getErrors, getPDF, getZoom, } from "./ViewerContext.svelte"; + import Error from "../common/Error.svelte"; const documentStore = getDocument(); const currentPage = getCurrentPage(); @@ -32,42 +34,56 @@ $: scale = zoomToScale($zoom); $: sizes = document.page_spec ? pageSizes(document.page_spec) : []; $: sections = getSections(document); + $: errors = getErrors(); onMount(() => { - $pdf.then((p) => { - // handle missing page_spec - if (sizes.length === 0) { - sizes = Array(p.numPages).fill([0, 0]); - } + $pdf + .then((p) => { + // handle missing page_spec + if (sizes.length === 0) { + sizes = Array(p.numPages).fill([0, 0]); + } - if ($currentPage > 1) { - scrollToPage($currentPage); - } + if ($currentPage > 1) { + scrollToPage($currentPage); + } - // @ts-ignore - window.pdf = p; - }); + // @ts-ignore + window.pdf = p; + }) + .catch((e) => { + console.error(e); + errors.update((errs) => [...errs, e]); + }); }); let width: number; -
remToPx(70)} -> - {#each sizes as [width, height], n} - {@const page_number = n + 1} - {#if sections[n]} -

- {sections[n].title} -

- {/if} - - {/each} -
+{#if Boolean($errors?.length)} + + {#each $errors as error} +

{String(error)}

+ {/each} +
+{:else} +
remToPx(70)} + > + {#each sizes as [width, height], n} + {@const page_number = n + 1} + {#if sections[n]} +

+ {sections[n].title} +

+ {/if} + + {/each} +
+{/if}