Merge branch 'main' into fix-#41-db-migration-Signature_recipientId_fkey

This commit is contained in:
Timur Ercan
2023-04-11 15:34:32 +02:00
committed by GitHub
7 changed files with 128 additions and 100 deletions

View File

@ -3,7 +3,7 @@ import { addDigitalSignature } from "@documenso/signing/addDigitalSignature";
import { sendMail } from "./sendMail";
import { Document as PrismaDocument } from "@prisma/client";
export const sendSigningDoneMail = async (recipient: any, document: PrismaDocument, user: any) => {
export const sendSigningDoneMail = async (document: PrismaDocument, user: any) => {
await sendMail(
user.email,
`Completed: "${document.title}"`,

View File

@ -12,27 +12,36 @@ export async function insertTextInPDF(
): Promise<string> {
const fontBytes = fs.readFileSync("public/fonts/Qwigley-Regular.ttf");
const existingPdfBytes = pdfAsBase64;
const pdfDoc = await PDFDocument.load(pdfAsBase64);
const pdfDoc = await PDFDocument.load(existingPdfBytes);
pdfDoc.registerFontkit(fontkit);
const customFont = await pdfDoc.embedFont(fontBytes);
const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica);
const font = await pdfDoc.embedFont(useHandwritingFont ? fontBytes : StandardFonts.Helvetica);
const pages = pdfDoc.getPages();
const pdfPage = pages[page];
const textSize = useHandwritingFont ? 50 : 15;
const textWidth = customFont.widthOfTextAtSize(text, textSize);
const textHeight = customFont.heightAtSize(textSize);
const textWidth = font.widthOfTextAtSize(text, textSize);
const textHeight = font.heightAtSize(textSize);
const fieldSize = { width: 192, height: 64 };
const invertedYPosition = pdfPage.getHeight() - positionY - fieldSize.height;
// Because pdf-lib use a bottom-left coordinate system, we need to invert the y position
// we then center the text in the middle by adding half the height of the text
// plus the height of the field and divide the result by 2
const invertedYPosition =
pdfPage.getHeight() - positionY - (fieldSize.height + textHeight / 2) / 2;
// We center the text by adding the width of the field, subtracting the width of the text
// and dividing the result by 2
const centeredXPosition = positionX + (fieldSize.width - textWidth) / 2;
pdfPage.drawText(text, {
x: positionX,
x: centeredXPosition,
y: invertedYPosition,
size: textSize,
font: useHandwritingFont ? customFont : helveticaFont,
color: rgb(0, 0, 0),
font,
});
const pdfAsUint8Array = await pdfDoc.save();

View File

@ -24,7 +24,7 @@ async function createUser(userData: { email: string; password: string }) {
async function main() {
console.info("Start seeding...");
const password = "123456789";
const email = "example6@documenso.com";
const email = "example@documenso.com";
const user = await createUser({
email: email,
password: await hashPassword(password),