Skip to content

Build your personal knowledge base with Trilium Notes

fix(print_preview): show render errors in the preview pane

Elian Doran177e51503c4c
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 44878359c1..e8e97c0192 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3903,7 +3903,6 @@
"page_size": "Page size",
"scale": "Scale",
"margins": "Margins",
- "render_error": "Unable to render PDF with the current settings. Please check the margins and scale.",
"margins_default": "Default",
"margins_none": "None",
"margins_minimum": "Minimum",
@@ -3915,7 +3914,9 @@
"page_ranges": "Pages",
"page_ranges_hint": "Leave empty to print all pages.",
"page_ranges_invalid": "Invalid format. Use e.g. 1-5, 8, 11-13.",
- "page_ranges_placeholder": "e.g. 1-5, 8, 11-13"
+ "page_ranges_placeholder": "e.g. 1-5, 8, 11-13",
+ "render_error_title": "Unable to render PDF with the current settings",
+ "render_error_description": "Please check the margins and scale."
},
"pdf": {
"attachments_one": "{{count}} attachment",
diff --git a/apps/client/src/widgets/dialogs/print_preview.css b/apps/client/src/widgets/dialogs/print_preview.css
index 8710892075..8071cd99ff 100644
--- a/apps/client/src/widgets/dialogs/print_preview.css
+++ b/apps/client/src/widgets/dialogs/print_preview.css
@@ -32,11 +32,16 @@ body.desktop .print-preview-dialog .modal-content-with-sidebar {
width: 100%;
}
- .print-preview-pane iframe {
+ .print-preview-pane iframe,
+ .print-preview-pane > .no-items {
position: absolute;
inset: 0;
}
+ .print-preview-pane > .no-items {
+ height: auto;
+ }
+
.print-preview-loading-overlay {
position: absolute;
inset: 0;
diff --git a/apps/client/src/widgets/dialogs/print_preview.tsx b/apps/client/src/widgets/dialogs/print_preview.tsx
index 76a1f5007f..bb32f990df 100644
--- a/apps/client/src/widgets/dialogs/print_preview.tsx
+++ b/apps/client/src/widgets/dialogs/print_preview.tsx
@@ -13,6 +13,7 @@ import FormSelect from "../react/FormSelect";
import FormTextBox, { FormTextBoxWithUnit } from "../react/FormTextBox";
import { useNoteLabelBoolean, useNoteLabelWithDefault, useTriliumEvent } from "../react/hooks";
import Modal from "../react/Modal";
+import NoItems from "../react/NoItems";
import Slider from "../react/Slider";
import PdfViewer from "../type_widgets/file/PdfViewer";
import OptionsRow from "../type_widgets/options/components/OptionsRow";
@@ -96,6 +97,7 @@ export default function PrintPreviewDialog() {
const [pdfUrl, setPdfUrl] = useState<string>();
const [note, setNote] = useState<FNote>();
const [loading, setLoading] = useState(false);
+ const [error, setError] = useState<string>();
const bufferRef = useRef<Uint8Array>();
const notePathRef = useRef("");
const pdfUrlRef = useRef<string>();
@@ -162,19 +164,16 @@ export default function PrintPreviewDialog() {
toast.closePersistent("printing");
if (error) {
setLoading(false);
+ setError(error);
+ bufferRef.current = undefined;
if (pdfUrlRef.current) {
URL.revokeObjectURL(pdfUrlRef.current);
pdfUrlRef.current = undefined;
setPdfUrl(undefined);
}
- toast.showPersistent({
- id: "print-preview-error",
- icon: "bx bx-error-circle",
- message: `${t("print_preview.render_error")}\n\n${error}`
- });
return;
}
- toast.closePersistent("print-preview-error");
+ setError(undefined);
if (buffer) {
updatePreview(buffer);
}
@@ -216,7 +215,7 @@ export default function PrintPreviewDialog() {
function handleClose() {
setShown(false);
isFirstGenerationRef.current = true;
- toast.closePersistent("print-preview-error");
+ setError(undefined);
if (pdfUrlRef.current) {
URL.revokeObjectURL(pdfUrlRef.current);
pdfUrlRef.current = undefined;
@@ -407,7 +406,7 @@ export default function PrintPreviewDialog() {
icon={destination === DESTINATION_PDF ? "bx-file" : "bx-printer"}
className="btn-primary"
onClick={handlePrimaryAction}
- disabled={loading}
+ disabled={loading || (destination === DESTINATION_PDF && !!error)}
/>
</>
}
@@ -418,6 +417,12 @@ export default function PrintPreviewDialog() {
<span class="bx bx-loader-circle bx-spin" />
</div>
)}
+ {error && (
+ <NoItems icon="bx bx-error-circle" text={t("print_preview.render_error_title")}>
+ <p>{t("print_preview.render_error_description")}</p>
+ <p>{error}</p>
+ </NoItems>
+ )}
{pdfUrl && <PdfViewer pdfUrl={pdfUrl} toolbar={false} disableSelection minPixelRatio={2} />}
</div>
</Modal>