Closed simonmumenthaler closed 8 months ago
This would be very helpful indeed! Any updates on this?
Unfortunately not. I have a few days off at the end of the month in which I would like to overhaul this module and implement this.
Hey, Roger. Instead of adding the entire "render only QR Code" functionality, would it be easier just to add a static ID to the SVG inside the _renderQRCode method? @simonmumenthaler, I used height & width targeting to identify the QR Code, as it is statically defined inside the library.
const svg = new SwissQRBill.SVG(data.qrCodeData, data.options);
const findQRCode = useCallback((element) => { if (element && element.hasChildNodes()) { return Array.from(element.children).find( (el) => el.width?.baseVal?.valueAsString === "46mm" && el.height?.baseVal?.valueAsString === "46mm"
as Node;
}
return
;
findQRCode(svg.element)`
Hope it helps.
All the best! Alex
SwissQRBill v4 now offers a separate class SwissQRCode
for PDF and SVG to make this possible. This will create a "SwissQRCode" including the swiss cross in the center.
Example:
import { writeFileSync } from "node:fs";
import { SwissQRCode } from "swissqrbill/svg";
const data = {
amount: 1994.75,
creditor: {
account: "CH44 3199 9123 0008 8901 2",
address: "Musterstrasse",
buildingNumber: 7,
city: "Musterstadt",
country: "CH",
name: "SwissQRBill",
zip: 1234
},
currency: "CHF",
debtor: {
address: "Musterstrasse",
buildingNumber: 1,
city: "Musterstadt",
country: "CH",
name: "Peter Muster",
zip: 1234
},
reference: "21 00000 00003 13947 14300 09017"
};
const svg = new SwissQRCode(data);
writeFileSync("qr-code.svg", svg.toString());
I'm looking for a way to generate the QR Code only as SVG - the method used in the SVG Class is the
generateQRCode
Unfortunately this function is not exported (also no deep import possible as the package.json does not list this file).Therefore: could you export this function?