// pdf.js — renders a branded, signed document (Einwilligung / Behandlungsvertrag) to // PDF using Electron's own printToPDF, no extra PDF library needed. A hidden // BrowserWindow loads a self-contained HTML string (logo and signature inlined as // base64 data URIs — a data: page can't reliably load file:// resources) and prints it. "use strict"; const { BrowserWindow } = require("electron"); function escapeHtml(s) { return String(s ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c])); } async function renderPdf({ title, ownerBlockHtml, bodyHtml, signatureDataUri, signedInfoHtml, logoDataUri }) { const html = `${escapeHtml(title)}
${logoDataUri ? `` : ""}
TIERHEILPRAXIS IRIS HACK
Iris Hack, Elisabethstr. 17, 84489 Burghausen, Deutschland
Tel: +49 160 3408101 · info@tierheilpraxis-hack.de

${escapeHtml(title)}

${ownerBlockHtml}
${bodyHtml}
${signedInfoHtml || signatureDataUri ? `
${signedInfoHtml}${signatureDataUri ? `` : ""}
` : ""} `; const win = new BrowserWindow({ show: false, webPreferences: { offscreen: false } }); try { await win.loadURL("data:text/html;charset=utf-8," + encodeURIComponent(html)); const buffer = await win.webContents.printToPDF({ printBackground: true, pageSize: "A4", margins: { marginType: "default" }, }); return buffer; } finally { win.destroy(); } } module.exports = { renderPdf };