Hide signature widget border for FirmaEC and bump to 1.2.23

This commit is contained in:
2026-05-22 14:02:56 -05:00
parent 2a0f272af1
commit 5ed70766b9
9 changed files with 45 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "linkedsign-backend",
"version": "1.2.22",
"version": "1.2.23",
"private": true,
"description": "Initial backend for LinkedSign",
"main": "src/server.js",
+32 -2
View File
@@ -1,7 +1,7 @@
const fs = require('fs/promises');
const path = require('path');
const QRCode = require('qrcode');
const { PDFDocument, rgb, StandardFonts } = require('pdf-lib');
const { PDFDocument, PDFArray, PDFName, PDFNumber, rgb, StandardFonts } = require('pdf-lib');
const { pdflibAddPlaceholder } = require('@signpdf/placeholder-pdf-lib');
const { SignPdf } = require('@signpdf/signpdf');
const { P12Signer } = require('@signpdf/signer-p12');
@@ -87,6 +87,34 @@ function buildLocalizedSignatureTimestamp({ locale, timeZone } = {}) {
}
}
function hideSignatureWidgetBorder(pdfDoc, pageIndex) {
const page = pdfDoc.getPages()[pageIndex];
if (!page) return;
const annotations = page.node.lookupMaybe(PDFName.of('Annots'), PDFArray);
if (!annotations || annotations.size() === 0) return;
const widgetRef = annotations.get(annotations.size() - 1);
const widget = pdfDoc.context.lookup(widgetRef);
if (!widget) return;
const zeroBorder = PDFArray.withContext(pdfDoc.context);
zeroBorder.push(PDFNumber.of(0));
zeroBorder.push(PDFNumber.of(0));
zeroBorder.push(PDFNumber.of(0));
widget.set(PDFName.of('Border'), zeroBorder);
widget.set(PDFName.of('BS'), pdfDoc.context.obj({
Type: 'Border',
W: 0,
S: 'S',
}));
widget.set(PDFName.of('MK'), pdfDoc.context.obj({
BC: [],
BG: [],
}));
}
// ── Style: CLASSIC (blue bar + DS badge) ──────────────────────────────────────
async function drawStyleClassic(pdfDoc, page, sx, sy, sw, sh, { signerName, reason, dateStr, timeStr, location }) {
const f1 = await pdfDoc.embedFont(StandardFonts.HelveticaBold);
@@ -391,6 +419,7 @@ const signPdf = async ({
// ── Add cryptographic signature placeholder ───────────────────────
const pdfDocForSign = await PDFDocument.load(pdfWithStamp);
const placeholderPageIndex = Math.min(page, pdfDocForSign.getPageCount() - 1);
pdflibAddPlaceholder({
pdfDoc: pdfDocForSign,
reason: reason || 'Firma digital',
@@ -399,8 +428,9 @@ const signPdf = async ({
location: location || '',
signatureLength: 32768,
rect: [sx, sy, sx + sw, sy + sh],
pageIndex: Math.min(page, pdfDocForSign.getPageCount() - 1),
pageIndex: placeholderPageIndex,
});
hideSignatureWidgetBorder(pdfDocForSign, placeholderPageIndex);
const pdfWithPlaceholder = Buffer.from(await pdfDocForSign.save({ useObjectStreams: false }));