mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-16 19:57:52 +01:00
web: get rid of print-js lib for printing
This commit is contained in:
committed by
Abdullah Atta
parent
36bf7c5cc6
commit
69dee3be78
1049
apps/web/package-lock.json
generated
1049
apps/web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -51,7 +51,6 @@
|
||||
"pdfjs-dist": "3.6.172",
|
||||
"phone": "^3.1.14",
|
||||
"platform": "^1.3.6",
|
||||
"print-js": "^1.6.0",
|
||||
"qclone": "^1.2.0",
|
||||
"react-dropzone": "^11.4.2",
|
||||
"react-hot-toast": "^2.2.0",
|
||||
|
||||
@@ -30,20 +30,31 @@ export async function exportToPDF(
|
||||
content: string
|
||||
): Promise<boolean> {
|
||||
if (!content) return false;
|
||||
const { default: printjs } = await import("print-js");
|
||||
return new Promise((resolve) => {
|
||||
printjs({
|
||||
printable: content.replaceAll(/<p [a-z\-="]*><\/p>/gm, "<p> </p>"),
|
||||
targetStyles: "*",
|
||||
type: "raw-html",
|
||||
documentTitle: title,
|
||||
header: '<h3 class="custom-h3">My custom header</h3>',
|
||||
onPrintDialogClose: () => {
|
||||
resolve(false);
|
||||
},
|
||||
onError: () => resolve(false)
|
||||
});
|
||||
resolve(true);
|
||||
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const iframe = document.createElement("iframe");
|
||||
iframe.srcdoc = content.replaceAll(/<p(.+?)><\/p>/gm, "<p$1><br/></p>");
|
||||
iframe.style.position = "fixed";
|
||||
iframe.style.right = "0";
|
||||
iframe.style.bottom = "0";
|
||||
iframe.style.width = "0";
|
||||
iframe.style.height = "0";
|
||||
iframe.style.border = "0";
|
||||
|
||||
iframe.onload = () => {
|
||||
if (!iframe.contentWindow) return;
|
||||
if (iframe.contentDocument) iframe.contentDocument.title = title;
|
||||
iframe.contentWindow.onbeforeunload = () => closePrint(false);
|
||||
iframe.contentWindow.onafterprint = () => closePrint(true);
|
||||
iframe.contentWindow.print();
|
||||
};
|
||||
|
||||
function closePrint(result: boolean) {
|
||||
document.body.removeChild(iframe);
|
||||
resolve(result);
|
||||
}
|
||||
|
||||
document.body.appendChild(iframe);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user