Created
May 10, 2023 10:50
-
-
Save manniru/0361b459aa2fa6c41bbbaea5a0171f3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PDFDocument from "pdfkit"; | |
import qr from "qr-image"; | |
import bg from "src/esys/images/bg"; | |
import coa from "src/esys/images/coa"; | |
import sign from "src/esys/images/sign"; | |
const irs = JSON.parse(`{ | |
"name": "GOMBE STATE INTERNAL REVENUE SERVICE - IGR PLATFORM", | |
"shorName": "GIRS" | |
} | |
`); | |
const payment = JSON.parse(`{ | |
"systemName": "170282441793", | |
"merchantName": "0", | |
"merchantAccount": "MUHAMMAD MANNIR AHMAD", | |
"beneficiaryName": "08033099431 / Payer Email: [email protected]", | |
"beneficiaryAccount": "1019852880", | |
"serviceTypeId": "1837590472", | |
"revenueHead": "HEAD 108 MISCELLANEOUS", | |
"revenueCategory": "POLYTECHNIC OF SOKOTO", | |
"payerName": "TEST PAYER", | |
"payerPhone": "08000000001", | |
"payerEmail": "[email protected]", | |
"date": "Saturday 16/03/2019 07:03:14", | |
"description": "REGISTRATION / PRE ND /", | |
"orderId": "1552760645169", | |
"amount": 2800, | |
"rrr": 180287279452 | |
} | |
`); | |
function textInRowFirst(doc: PDFKit.PDFDocument, text: string, heigth: number) { | |
doc.y = heigth; | |
doc.x = 50; | |
doc.fillColor("black"); | |
doc.text(text, { | |
paragraphGap: 5, | |
indent: 5, | |
align: "justify", | |
columns: 1, | |
}); | |
return doc; | |
} | |
function row(doc: PDFKit.PDFDocument, heigth: number) { | |
doc | |
.lineJoin("miter") | |
.rect(50, heigth, 490, 20) | |
// .fillAndStroke("#ccffcc", "black") | |
.stroke(); | |
return doc; | |
} | |
const generateReceipt = (req: any, res: any) => { | |
// res.setHeader("Content-disposition", "attachment; filename=testFile.pdf"); | |
/* Download | |
res.writeHead(200, { | |
"Content-Type": "application/pdf", | |
"Content-Disposition": "attachment; filename=receipt.pdf" | |
}); | |
*/ | |
const doc = new PDFDocument({ | |
size: [419.53, 595.28], | |
layout: "landscape", | |
margins: { | |
// by default, all are 72 | |
top: 20, | |
bottom: 20, | |
left: 20, | |
right: 20, | |
}, | |
info: { | |
Title: "IGR.NG - Receipt", | |
Author: "author", // the name of the author | |
Keywords: "pdf;javascript", // keywords associated with the document | |
}, | |
}); | |
doc.image(bg, 0, 0, { height: 415.53, width: 595.28 }); | |
doc.image(coa, 250, 40, { height: 68, width: 80 }); | |
doc.image(sign, 260, 340, { height: 30 }); | |
doc.image( | |
qr.imageSync( | |
`${payment.payerName} / ${payment.merchantAccount} / ${payment.serviceTypeId} / ${payment.rrr} / ${payment.amount} `, | |
{ type: "png" } | |
), | |
50, | |
50, | |
{ height: 80, width: 80 } | |
); | |
let y = 90; | |
doc | |
.fontSize(10) | |
.font("Helvetica-Bold") | |
.text(`2019/03/16/SOK/1552760571259`, 370, y - 40) | |
.fontSize(12) | |
// .text(payment.systemName, 10, 40, { align: "center" }) | |
.text(`e-REVENUE RECEIPT`, 10, y + 20, { align: "center" }) | |
.text(`${irs.name}`, 10, y + 40, { | |
align: "center", | |
}) | |
.fontSize(10) | |
.text(`http://scabs.com.ng`, 10, y + 55, { align: "center" }); | |
doc.fontSize(10); | |
doc.moveDown(); | |
doc.text(`PAYMENT DETAILS`, 55, 166); | |
doc.text(`${irs.name}`, 300, 166); | |
doc.rect(50, 160, 150, 20).stroke(); //doc.x | |
// doc.rect(20, 100, 555, 15).fillAndStroke("#ffffcc", "black"); // | |
// doc.fill("#000").text("BILLER INFORMATION", { align: "center" }); | |
const h = 185; | |
row(doc, h); | |
row(doc, h + 20); | |
row(doc, h + 40); | |
row(doc, h + 60); | |
row(doc, h + 80); | |
row(doc, h + 100); | |
row(doc, h + 120); | |
row(doc, h + 140); | |
textInRowFirst(doc, `TIN No.: 170282441793`, h + 6); | |
textInRowFirst(doc, "Payer No: 0", h + 26); | |
textInRowFirst(doc, "Payer Name: MUHAMMAD MANNIR AHMAD", h + 46); | |
textInRowFirst(doc, "Payer Phone: 08033099431", h + 66); | |
textInRowFirst(doc, "Amount Paid: NGN 25,000", h + 86); | |
textInRowFirst(doc, "Revenue Head: HEAD 108 MISCELLANEOUS", h + 106); | |
textInRowFirst(doc, "Revenue Category: SCHOOL FEES", h + 126); | |
textInRowFirst( | |
doc, | |
"Payment Details: Payment Details: Others (1550931770215 / 170282441793)", | |
h + 146 | |
); | |
y = 350; | |
doc | |
.fontSize(7) | |
.text(`SOKOTO STATE GOVERNMENT e-REVENUE MANAGEMENT SYSTEM`, 310, y) | |
.text(`CHAIRMAN`, 55, y + 20, { | |
align: "center", | |
}); | |
doc.pipe(res); | |
doc.end(); | |
}; | |
module.exports = (req: any, res: any) => { | |
generateReceipt(req, res); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment