How can I convert a bpmn file into pdf?
Use this: https://github.com/bpmn-io/bpmn-to-image
async function downloadPDF() {
try {
const { svg } = await modeler.saveSVG();
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
const parser = new DOMParser();
const svgDocument = parser.parseFromString(svg, "image/svg+xml");
const svgElement = svgDocument.querySelector("svg");
if (!svgElement) {
throw new Error("El SVG no pudo ser parseado correctamente.");
}
const svgWidth = parseFloat(svgElement.getAttribute("width")) || 500;
const svgHeight = parseFloat(svgElement.getAttribute("height")) || 500;
canvas.width = svgWidth;
canvas.height = svgHeight;
const v = await Canvg.from(ctx, svg, { ignoreDimensions: false });
await v.render();
const doc = new jsPDF();
const pdfWidth = 190;
const pdfHeight = (svgHeight / svgWidth) * pdfWidth;
const imgData = canvas.toDataURL("image/png");
doc.addImage(imgData, "PNG", 10, 10, pdfWidth, pdfHeight);
doc.save("diagram.pdf");
} catch (err) {
console.error("Error generating PDF: ", err);
}
}