gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 04/04: fix: use a half decent pdf saving mechanism


From: gnunet
Subject: [taler-wallet-core] 04/04: fix: use a half decent pdf saving mechanism
Date: Sun, 11 Aug 2024 19:34:08 +0200

This is an automated email from the git hooks/post-receive script.

nora-grothoff pushed a commit to branch master
in repository wallet-core.

commit 6307c6d661836512ba91adc4eb03cd5af40dd47b
Author: Nullptrderef <nullptrderef@proton.me>
AuthorDate: Sun Aug 11 19:33:56 2024 +0200

    fix: use a half decent pdf saving mechanism
---
 .../src/paths/instance/templates/qr/QrPage.tsx     | 28 ++++++++++++----------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git 
a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx 
b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx
index f66fdaa83..c66361e17 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/qr/QrPage.tsx
@@ -87,21 +87,25 @@ export function QrPage({ id: templateId, onBack }: Props): 
VNode {
 
 function saveAsPDF(name: string): void {
   // TODO: Look into using media queries in the current page, to print the 
current page, instead of opening a new window
-  const printWindow = window.open("", "", "height=400,width=800");
-  if (!printWindow) return;
+
   const divContents = document.getElementById("printThis");
   if (!divContents) return;
-  printWindow.document.write(
-    `<!DOCTYPE html><html><head><title>Order template for 
${name}</title><style>`,
-  );
-  printWindow.document.write("</style></head><body>&nbsp;</body></html>");
-  printWindow.document.close();
-  printWindow.document.body.appendChild(divContents.cloneNode(true));
+
+  let dom = `<!DOCTYPE html>
+<html>
+  <head>
+    <title>Order template for ${name}</title>
+  </head>
+  <body>
+    ${divContents.outerHTML}
+  </body>
+</html>`;
+  const blobUrl = URL.createObjectURL(new Blob([dom]));
+  const printWindow = window.open(blobUrl, "", "height=400,width=800");
+  if (!printWindow) return;
   printWindow.addEventListener("load", () => {
     printWindow.print();
-
-    // Why is the close commented out? Print is synchronous
-    //  ~ Nullptrderef
-    // printWindow.close();
+    printWindow.close();
+    URL.revokeObjectURL(blobUrl);
   });
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]