mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 19:21:39 +10:00
fix: insert horizontal field into pdf
This commit is contained in:
@ -331,36 +331,75 @@ export const insertFieldInPDF = async (pdf: PDFDocument, field: FieldWithSignatu
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const selected = field.customText.split(',');
|
const selected = field.customText.split(',');
|
||||||
|
const direction = meta.data.direction ?? 'vertical';
|
||||||
|
|
||||||
const topPadding = 12;
|
const topPadding = 12;
|
||||||
const leftRadioPadding = 8;
|
const leftRadioPadding = 8;
|
||||||
const leftRadioLabelPadding = 12;
|
const leftRadioLabelPadding = 12;
|
||||||
const radioSpaceY = 13;
|
const radioSpaceY = 13;
|
||||||
|
|
||||||
for (const [index, item] of (values ?? []).entries()) {
|
if (direction === 'horizontal') {
|
||||||
const offsetY = index * radioSpaceY + topPadding;
|
let currentX = leftRadioPadding;
|
||||||
|
let currentY = topPadding;
|
||||||
|
const maxWidth = pageWidth - fieldX - leftRadioPadding * 2;
|
||||||
|
|
||||||
const radio = pdf.getForm().createRadioGroup(`radio.${field.secondaryId}.${index}`);
|
for (const [index, item] of (values ?? []).entries()) {
|
||||||
|
const radio = pdf.getForm().createRadioGroup(`radio.${field.secondaryId}.${index}`);
|
||||||
|
|
||||||
// Draw label.
|
const labelText = item.value.includes('empty-value-') ? '' : item.value;
|
||||||
page.drawText(item.value.includes('empty-value-') ? '' : item.value, {
|
const labelWidth = font.widthOfTextAtSize(labelText, 12);
|
||||||
x: fieldX + leftRadioPadding + leftRadioLabelPadding,
|
const itemWidth = leftRadioLabelPadding + labelWidth + 16;
|
||||||
y: pageHeight - (fieldY + offsetY),
|
|
||||||
size: 12,
|
|
||||||
font,
|
|
||||||
rotate: degrees(pageRotationInDegrees),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Draw radio button.
|
if (currentX + itemWidth > maxWidth && index > 0) {
|
||||||
radio.addOptionToPage(item.value, page, {
|
currentX = leftRadioPadding;
|
||||||
x: fieldX + leftRadioPadding,
|
currentY += radioSpaceY;
|
||||||
y: pageHeight - (fieldY + offsetY),
|
}
|
||||||
height: 8,
|
|
||||||
width: 8,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (selected.includes(item.value)) {
|
page.drawText(labelText, {
|
||||||
radio.select(item.value);
|
x: fieldX + currentX + leftRadioLabelPadding,
|
||||||
|
y: pageHeight - (fieldY + currentY),
|
||||||
|
size: 12,
|
||||||
|
font,
|
||||||
|
rotate: degrees(pageRotationInDegrees),
|
||||||
|
});
|
||||||
|
|
||||||
|
radio.addOptionToPage(item.value, page, {
|
||||||
|
x: fieldX + currentX,
|
||||||
|
y: pageHeight - (fieldY + currentY),
|
||||||
|
height: 8,
|
||||||
|
width: 8,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selected.includes(item.value)) {
|
||||||
|
radio.select(item.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentX += itemWidth;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const [index, item] of (values ?? []).entries()) {
|
||||||
|
const offsetY = index * radioSpaceY + topPadding;
|
||||||
|
|
||||||
|
const radio = pdf.getForm().createRadioGroup(`radio.${field.secondaryId}.${index}`);
|
||||||
|
|
||||||
|
page.drawText(item.value.includes('empty-value-') ? '' : item.value, {
|
||||||
|
x: fieldX + leftRadioPadding + leftRadioLabelPadding,
|
||||||
|
y: pageHeight - (fieldY + offsetY),
|
||||||
|
size: 12,
|
||||||
|
font,
|
||||||
|
rotate: degrees(pageRotationInDegrees),
|
||||||
|
});
|
||||||
|
|
||||||
|
radio.addOptionToPage(item.value, page, {
|
||||||
|
x: fieldX + leftRadioPadding,
|
||||||
|
y: pageHeight - (fieldY + offsetY),
|
||||||
|
height: 8,
|
||||||
|
width: 8,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (selected.includes(item.value)) {
|
||||||
|
radio.select(item.value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user