mirror of
https://github.com/documenso/documenso.git
synced 2025-11-22 20:51:33 +10:00
♻️ 🚧 date and text field
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
import { FieldType } from "@prisma/client";
|
||||
|
||||
export const createField = function addField(
|
||||
export const createField = (
|
||||
e: any,
|
||||
page: number,
|
||||
selectedRecipient: any,
|
||||
type: FieldType = FieldType.SIGNATURE
|
||||
): any {
|
||||
type: FieldType = FieldType.SIGNATURE,
|
||||
customText = ""
|
||||
): any => {
|
||||
var rect = e.target.getBoundingClientRect();
|
||||
const fieldSize = { width: 192, height: 96 };
|
||||
var newFieldX = e.clientX - rect.left - fieldSize.width / 2; //x position within the element.
|
||||
@ -25,6 +26,7 @@ export const createField = function addField(
|
||||
positionX: newFieldX.toFixed(0),
|
||||
positionY: newFieldY.toFixed(0),
|
||||
Recipient: selectedRecipient,
|
||||
customText: customText,
|
||||
};
|
||||
|
||||
return signatureField;
|
||||
|
||||
@ -7,7 +7,8 @@ export async function insertTextInPDF(
|
||||
text: string,
|
||||
positionX: number,
|
||||
positionY: number,
|
||||
page: number = 0
|
||||
page: number = 0,
|
||||
useHandwritingFont = true
|
||||
): Promise<string> {
|
||||
const fontBytes = fs.readFileSync("public/fonts/Qwigley-Regular.ttf");
|
||||
|
||||
@ -16,10 +17,11 @@ export async function insertTextInPDF(
|
||||
const pdfDoc = await PDFDocument.load(existingPdfBytes);
|
||||
pdfDoc.registerFontkit(fontkit);
|
||||
const customFont = await pdfDoc.embedFont(fontBytes);
|
||||
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
|
||||
|
||||
const pages = pdfDoc.getPages();
|
||||
const pdfPage = pages[page];
|
||||
const textSize = 50;
|
||||
const textSize = useHandwritingFont ? 50 : 15;
|
||||
const textWidth = customFont.widthOfTextAtSize(text, textSize);
|
||||
const textHeight = customFont.heightAtSize(textSize);
|
||||
|
||||
@ -27,7 +29,7 @@ export async function insertTextInPDF(
|
||||
x: positionX, // todo adjust for exact field size
|
||||
y: pdfPage.getHeight() - positionY - textHeight / 2, // todo adjust for exact field size
|
||||
size: textSize,
|
||||
font: customFont,
|
||||
font: useHandwritingFont ? customFont : helveticaFont,
|
||||
color: rgb(0, 0, 0),
|
||||
});
|
||||
|
||||
|
||||
@ -115,6 +115,7 @@ model Field {
|
||||
page Int
|
||||
positionX Int @default(0)
|
||||
positionY Int @default(0)
|
||||
customText String
|
||||
Document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
Recipient Recipient? @relation(fields: [recipientId], references: [id], onDelete: Cascade)
|
||||
Signature Signature?
|
||||
|
||||
Reference in New Issue
Block a user