 |
| PDFKIT TO DESIGN CERIFICATE USING NODEJS AND EXPRESSJS | PDF DESIGN USING TYPESCRIP AND FIREBASE FUNCTIONS SECOND DESIGN |
const express = require('express')
const app = express()
const port = 4200
const PDFDocument = require('pdfkit');
const fs = require('fs');
const pdfTable = require("voilab-pdf-table");
app.get('/', (req, res) => {
res.send('bk');
});
const doc = new PDFDocument({
layout: 'portrait',
size: 'A4',
});
const distanceMargin = 18;
let grad = doc.linearGradient(50, 0, 150, 100);
grad.stop(0, '#542057')
.stop(1, '#240460');
doc
.fillAndStroke(grad)
.lineWidth(20)
.dash(5, { space: 2 })
.lineJoin('miter')
.rect(
distanceMargin,
distanceMargin,
doc.page.width - distanceMargin * 2,
doc.page.height - distanceMargin * 2,
)
.stroke();
const maxWidth = 140;
const maxHeight = 70;
doc
.fontSize(12)
.fill('#000000')
.text('Regd. By Govt. of India', {
align: 'left',
}
);
doc.image(
'assets/ansh.jpeg',
doc.page.width / 2 - maxWidth / 2,
60,
{
fit: [maxWidth, maxHeight],
align: 'center',
}
);
jumpLine(doc, 4);
doc
.fontSize(16)
.fill('#0027A7')
.text('Ansh Computer And Technical Institute Khalispur Varanasi', {
align: 'center',
}
);
// jumpLine(doc, 1);
doc
.fontSize(12)
.fill('#000000')
.text('An ISO 9001-2008 Certified Institute', {
align: 'center',
}
);
// jumpLine(doc, 1);
doc.image(
'assets/student.jpg',
430,
170,
{
fit: [90, 120],
align: 'right',
}
);
doc
.fontSize(14)
.font('Helvetica-Bold')
// .fill('#000000')
.text('Head Office : KHALISHPUR, VARANASI', {
align: 'center',
}
);
doc.moveDown();
function jumpLine(doc, lines) {
for (let index = 0; index < lines; index++) {
doc.moveDown();
}
}
jumpLine(doc, 3);
doc
.fontSize(16)
.fill('#0027A7')
.text('Regd. No.: SAC153/0104', {
align: 'left',
}
);
doc
.font('assets/enjelina.ttf')
.fontSize(14)
.fill('#021c27')
.text('This is cerify that Mr. / Miss. / Mrs. ', {
align: 'left',
continued: true
}
)
.font('assets/geraldine.ttf')
.text('Brijesh Kumar\n', {
}).font('assets/enjelina.ttf').text('S/o. / D/o. ', {
continued: true
})
.font('assets/geraldine.ttf').text('Radheshyam\n').font('assets/enjelina.ttf').text('has successfully completed the course ADCA (', { continued: true }).font('assets/geraldine.ttf').text('Advanced Diploma in Computer Application').font('assets/enjelina.ttf').text(') of duration 1Year to Branch ', {
continued: true
}).font('assets/geraldine.ttf').text('Ansh Computer And Technical Institute Khalispur Varanasi')
;
jumpLine(doc, 2);
const table = new pdfTable(doc.font('Helvetica').fillAndStroke("#000000").lineWidth(1).stroke(), {
align: 'center',
});
table.setColumnsDefaults({
headerBorder: ['L', 'T', 'B', 'R'],
border: ['L', 'T', 'B', 'R'],
align: 'center',
headerPadding: [8, 0, 0, 0],
});
table.addColumns([
{
id: 'sn',
width: 50,
header: 'S.No.',
padding: [5, 5, 5, 5],
},
{
id: 'exam',
width: 100,
align: 'center',
header: 'Exam.',
padding: [5, 5, 5, 5],
},
{
id: 'maxmarks',
width: 100,
align: 'center',
padding: [5, 5, 5, 5],
header: 'Max. Marks',
},
{
id: 'minmarks',
width: 100,
align: 'center',
padding: [5, 5, 5, 5],
header: 'Min. Marks',
},
{
id: 'marksobt',
width: 100,
align: 'center',
padding: [5, 5, 5, 5],
header: 'Marks. Obt.',
}
]);
table.addBody([
{ sn: '1.', exam: 1, maxmarks: 20.10, minmarks: 20.10, marksobt: 12 },
{ sn: '2.', exam: 1, maxmarks: 20.10, minmarks: 20.10, marksobt: 12 },
{ sn: '3.', exam: 1, maxmarks: 20.10, minmarks: 20.10, marksobt: 12 },
{ sn: '', exam: 'Total', maxmarks: 60.30, minmarks: 60.30, marksobt: 48 },
]);
doc
.fontSize(12)
.text('Subject:\n', 70, 552, {
align: 'left',
}
);
jumpLine(doc, 1);
doc
.fontSize(12)
.text('Grade:\n', 70, 630, {
align: 'left',
}
);
doc
.fontSize(12)
.text('Percentage:\n', {
align: 'left',
}
);
doc
.fontSize(12)
.text('Date of Issues:\n', {
align: 'left',
}
);
doc
.fontSize(14)
.fill('#FF0000')
.text('Authorised Signatory\n', {
align: 'right',
}
); doc
.fontSize(12)
.fill('#FF0000')
.text('Grade: ', 70, 755, {
align: 'left',
continued: true
}
).fontSize(8).text('85% and above A+,75%-84% A,65%-74% B+,55%-64% B,45%-55% C+,40%-45% C,Below 40% D', 70, 758);
doc.pipe(fs.createWriteStream('output.pdf'));
doc.end();
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})