Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 134 additions & 41 deletions src/signBasicForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,116 +62,209 @@ function signBasicForm (userData) {
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.addressLine1), {
drawText(courierFont.encodeText(userData.firstLineAddress), {
x: 180,
y: 507,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.addressLine2), {
drawText(courierFont.encodeText(userData.secondLineAddress), {
x: 180,
y: 488,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.addressLine3), {
drawText(courierFont.encodeText(userData.city), {
x: 180,
y: 470,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.postCode), {
drawText(courierFont.encodeText(userData.postcode), {
x: 405,
y: 470,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText("X"), {
x: 211,
y: 453,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.citizenCountry), {
x: 415,
y: 677,
x: 80,
y: 322,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText("X"), {
x: 50,
y: 245,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
})
);

existingPage1.addContentStreams(pdfDoc.register(newContentStream1));

const newContentStream2 = pdfDoc.createContentStream(
drawImage(SIGNATURE_PNG, {
x: 400,
y: 50,
width: SIGNATURE_PNG_WIDTH,
height: SIGNATURE_PNG_HEIGHT,
drawText(courierFont.encodeText("X"), {
x: 59,
y: 781,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.surname), {
x: 50,
y: 625,
drawText(courierFont.encodeText(userData.dateOfBirth[0]), {
x: 138,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.firstName), {
x: 50,
y: 585,
drawText(courierFont.encodeText(userData.dateOfBirth[1]), {
x: 152,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.addressLine1), {
x: 50,
y: 540,
drawText(courierFont.encodeText(userData.dateOfBirth[2]), {
x: 166,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.addressLine2), {
x: 50,
y: 521,
drawText(courierFont.encodeText(userData.dateOfBirth[3]), {
x: 180,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.addressLine3), {
x: 50,
y: 503,
drawText(courierFont.encodeText(userData.dateOfBirth[5]), {
x: 53,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.postCode), {
x: 205,
y: 480,
drawText(courierFont.encodeText(userData.dateOfBirth[6]), {
x: 67,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.citizenCountry), {
x: 415,
y: 677,
drawText(courierFont.encodeText(userData.dateOfBirth[8]), {
x: 96,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[9]), {
x: 110,
y: 728,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText("X"), {
x: 52,
y: 333,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[0]), {
x: 56,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[1]), {
x: 72,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[2]), {
x: 99,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[3]), {
x: 113,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[4]), {
x: 141,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[5]), {
x: 155,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[6]), {
x: 184,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[7]), {
x: 198,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.nin[8]), {
x: 229,
y: 641,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),

);

existingPage2.addContentStreams(pdfDoc.register(newContentStream2));

const pdfBytes = Buffer.from(PDFDocumentWriter.saveToBytes(pdfDoc)).toString('base64');
//const pdfBase64 = Buffer.from(PDFDocumentWriter.saveToBytes(pdfDoc)).toString('base64');

// const outputDir = `${__dirname}/../output`;
// const filePath = `${outputDir}/${Date.now()}.pdf`;
// if (!fs.existsSync(outputDir)){
// fs.mkdirSync(outputDir);
// }
// fs.writeFileSync(filePath, pdfBytes);
const pdfBytes = PDFDocumentWriter.saveToBytes(pdfDoc);
const outputDir = `${__dirname}/../output`;
const filePath = `${outputDir}/signBasicForm.pdf`;
if (!fs.existsSync(outputDir)){
fs.mkdirSync(outputDir);
}
fs.writeFileSync(filePath, pdfBytes);

// attachments.push(pdfBytes);
return pdfBytes;
//return pdfBase64;
}

module.exports = signBasicForm;
28 changes: 14 additions & 14 deletions src/signPostalForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,50 +114,50 @@ function signPostalPdf(userData) {
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[1]), {
x: 415,
y: 677,
x: 358,
y: 310,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[2]), {
x: 415,
y: 677,
x: 394,
y: 310,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[3]), {
x: 415,
y: 677,
x: 420,
y: 310,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[5]), {
x: 415,
y: 677,
x: 460,
y: 310,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[6]), {
x: 415,
y: 677,
x: 483,
y: 310,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[8]), {
x: 415,
y: 677,
x: 507,
y: 310,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
}),
drawText(courierFont.encodeText(userData.dateOfBirth[9]), {
x: 415,
y: 677,
x: 532,
y: 310,
font: COURIER_FONT,
size: 12,
colorRgb: [0, 0, 0],
Expand Down