Add optional signature upload to invoice PDF
Adds a drag-and-drop/click upload field on the invoice editor for an optional 420x210 JPG/PNG signature image. The signature is stored as part of invoice_data and rendered on the generated PDF directly above the QR code, right-aligned with sensible margins. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+10
-1
@@ -10,7 +10,7 @@ const { normalizeInvoiceData } = require('./invoice-data');
|
||||
const app = express();
|
||||
const sessionDurationMs = 1000 * 60 * 60 * 24 * 30;
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.json({ limit: '2mb' }));
|
||||
|
||||
const hashPassword = (password, salt = crypto.randomBytes(16).toString('hex')) => new Promise((resolve, reject) => {
|
||||
crypto.scrypt(password, salt, 64, (error, derivedKey) => {
|
||||
@@ -500,6 +500,7 @@ const renderInvoicePdf = async (document, invoice) => {
|
||||
width: 180,
|
||||
margin: 1
|
||||
}) : null;
|
||||
const signatureBuffer = data.signature ? Buffer.from(data.signature.split(',')[1], 'base64') : null;
|
||||
const pageWidth = document.page.width - document.page.margins.left - document.page.margins.right;
|
||||
const navy = '#183b56';
|
||||
const line = '#d8d4cc';
|
||||
@@ -573,6 +574,14 @@ const renderInvoicePdf = async (document, invoice) => {
|
||||
document.moveTo(document.page.margins.left, document.y).lineTo(document.page.margins.left + pageWidth, document.y)
|
||||
.strokeColor(navy).lineWidth(1.5).stroke();
|
||||
document.y += 12;
|
||||
if (signatureBuffer) {
|
||||
const signatureWidth = 145;
|
||||
const signatureHeight = signatureWidth / 2;
|
||||
const signatureGap = 8;
|
||||
const signatureX = document.page.margins.left + pageWidth - signatureWidth;
|
||||
document.image(signatureBuffer, signatureX, document.y, { fit: [signatureWidth, signatureHeight] });
|
||||
document.y += signatureHeight + signatureGap;
|
||||
}
|
||||
const paymentTop = document.y;
|
||||
document.roundedRect(document.page.margins.left, paymentTop, pageWidth, 165, 4).fillAndStroke('#f4f7fb', line);
|
||||
document.fillColor(navy).font(boldFont).fontSize(11).text('Platební údaje', document.page.margins.left + 10, paymentTop + 10);
|
||||
|
||||
Reference in New Issue
Block a user