From 9687b8739d3c3d8943e861aaf97bb8b4e28fc9df Mon Sep 17 00:00:00 2001 From: Phil Date: Sun, 28 Apr 2019 17:24:12 +0100 Subject: [PATCH 1/2] more data points added --- src/signBasicForm.js | 111 ++++++++++++++++++++++++++---------------- src/signPostalForm.js | 28 +++++------ 2 files changed, 84 insertions(+), 55 deletions(-) diff --git a/src/signBasicForm.js b/src/signBasicForm.js index 5a7ee0b..acd3d16 100644 --- a/src/signBasicForm.js +++ b/src/signBasicForm.js @@ -62,116 +62,145 @@ 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], + }) ); 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; diff --git a/src/signPostalForm.js b/src/signPostalForm.js index b1589d5..c4ce3c0 100644 --- a/src/signPostalForm.js +++ b/src/signPostalForm.js @@ -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], From 83bbd4fb9ba36914b00e7413ae6f20185120f7d7 Mon Sep 17 00:00:00 2001 From: Steve Musgrave Date: Sun, 28 Apr 2019 21:22:41 +0100 Subject: [PATCH 2/2] layout for basic form --- src/signBasicForm.js | 66 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/src/signBasicForm.js b/src/signBasicForm.js index acd3d16..783b5f6 100644 --- a/src/signBasicForm.js +++ b/src/signBasicForm.js @@ -185,7 +185,71 @@ function signBasicForm (userData) { 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));