From b865b59837f29ff7a88b8b18c0080f8d803ce5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Sch=C3=B6nb=C3=A4chler?= <42278642+schoero@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:36:39 +0100 Subject: [PATCH] refactor: clean up examples --- examples/browser-bundling-with-webpack/src/pdf.js | 2 +- examples/browser-pre-built-bundle/src/pdf.js | 11 +++-------- examples/node-cjs-javascript/src/pdf.js | 6 +++--- examples/node-cjs-javascript/src/svg.js | 1 + examples/node-esm-javascript/src/pdf.js | 6 +++--- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/examples/browser-bundling-with-webpack/src/pdf.js b/examples/browser-bundling-with-webpack/src/pdf.js index c7cf361..7463c2c 100644 --- a/examples/browser-bundling-with-webpack/src/pdf.js +++ b/examples/browser-bundling-with-webpack/src/pdf.js @@ -26,11 +26,11 @@ const pdf = new PDFDocument(); const qrBill = new SwissQRBill(data); qrBill.attachTo(pdf); -pdf.pipe(stream); stream.on("finish", () => { window.location.href = stream.toBlobURL("application/pdf"); console.log("PDF has been successfully created."); }); +pdf.pipe(stream); pdf.end(); diff --git a/examples/browser-pre-built-bundle/src/pdf.js b/examples/browser-pre-built-bundle/src/pdf.js index 9b6d7c2..14a9ff8 100644 --- a/examples/browser-pre-built-bundle/src/pdf.js +++ b/examples/browser-pre-built-bundle/src/pdf.js @@ -1,19 +1,14 @@ import { data } from "./data.js"; -const width = SwissQRBill.utils.mm2pt(210); -const height = SwissQRBill.utils.mm2pt(105); - -const pdf = new PDFDocument({ size: [width, height] }); -const stream = pdf.pipe(blobStream()); +const stream = new BlobStream(); +const pdf = new PDFDocument({ size: "A4" }); const qrBill = new SwissQRBill.pdf.SwissQRBill(data); -qrBill.attachTo(pdf); -pdf.end(); - stream.on("finish", () => { window.location.href = stream.toBlobURL("application/pdf"); }); qrBill.attachTo(pdf); +pdf.pipe(stream); pdf.end(); diff --git a/examples/node-cjs-javascript/src/pdf.js b/examples/node-cjs-javascript/src/pdf.js index 39a736e..04060d0 100644 --- a/examples/node-cjs-javascript/src/pdf.js +++ b/examples/node-cjs-javascript/src/pdf.js @@ -6,10 +6,10 @@ const data = require("./data"); const stream = createWriteStream("./output/swissqrbill.pdf"); -const pdf = new PDFDocument({ size: "A4" }); +const pdf = new PDFDocument(); const qrBill = new SwissQRBill(data); -pdf.pipe(stream); - qrBill.attachTo(pdf); + +pdf.pipe(stream); pdf.end(); diff --git a/examples/node-cjs-javascript/src/svg.js b/examples/node-cjs-javascript/src/svg.js index dc0399e..0fb8841 100644 --- a/examples/node-cjs-javascript/src/svg.js +++ b/examples/node-cjs-javascript/src/svg.js @@ -5,4 +5,5 @@ const data = require("./data.js"); const qrBill = new SwissQRBill(data); + writeFileSync("./output/swissqrbill.svg", qrBill.toString()); diff --git a/examples/node-esm-javascript/src/pdf.js b/examples/node-esm-javascript/src/pdf.js index 3a6158b..e5e320e 100644 --- a/examples/node-esm-javascript/src/pdf.js +++ b/examples/node-esm-javascript/src/pdf.js @@ -6,10 +6,10 @@ import { data } from "./data.js"; const stream = createWriteStream("./output/swissqrbill.pdf"); -const pdf = new PDFDocument({ size: "A4" }); +const pdf = new PDFDocument(); const qrBill = new SwissQRBill(data); -pdf.pipe(stream); - qrBill.attachTo(pdf); + +pdf.pipe(stream); pdf.end();