PDFKIT TO DESIGN CERIFICATE USING NODEJS AND EXPRESSJS | PDF DESIGN USING TYPESCRIP AND FIREBASE FUNCTIONS

PDFKIT TO DESIGN CERIFICATE USING NODEJS AND EXPRESSJS | PDF DESIGN USING TYPESCRIP AND FIREBASE FUNCTIONS
PDFKIT TO DESIGN CERIFICATE USING NODEJS AND EXPRESSJS | PDF DESIGN USING TYPESCRIP AND FIREBASE FUNCTIONS


 const express = require('express')

const app = express()
const port = 4200
const PDFDocument = require('pdfkit');
const fs = require('fs');

app.get('/', (req, res) => {
    res.send('bk');
});

const doc = new PDFDocument({
    layout: 'landscape',
    size: 'A4',
});
const distanceMargin = 18;
doc
    .fillAndStroke('#680f75')
    .lineWidth(20)
    .lineJoin('round')
    .rect(
        distanceMargin,
        distanceMargin,
        doc.page.width - distanceMargin * 2,
        doc.page.height - distanceMargin * 2,
    )
    .stroke();
const maxWidth = 140;
const maxHeight = 70;
doc.image(
    'assets/medal.png',
    doc.page.width / 2 - maxWidth / 2,
    60,
    {
        fit: [maxWidth, maxHeight],
        align: 'center',
    }
);

doc.moveDown();
function jumpLine(doc, lines) {
    for (let index = 0; index < lines; index++) {
        doc.moveDown();
    }
}
jumpLine(doc, 4);
doc
    .font('assets/geraldine.ttf')
    .fontSize(20)
    .fill('#021c27')
    .text('Advance Diploma in Computer Application', {
        align: 'center',
    }
    );

// jumpLine(doc, 1);
doc
    .fontSize(24)
    .fill('#021c27')
    .text('Certificate of complation', {
        align: 'center',
    }
    );
jumpLine(doc, 1);
doc
    .fontSize(16)
    .fill('#021c27')
    .text('Present to', {
        align: 'center',
    }
    );
jumpLine(doc, 1);
doc
    .fontSize(25)
    .fill('#021c27')
    .text('Brijesh kumar S/O Radheshyam', {
        align: 'center',
    }
    );


jumpLine(doc, 1);
doc
    .fontSize(20)
    .fill('#021c27')
    .text('of duration 1 YEAR and achieved the grade A during the course his/her performance was nice and wish him/her the best of luck for the future endeavors.', {
        align: 'center',
    }
    );

doc
    .fontSize(25)
    .fill('#021c27')
    .text(
        'Date:',
        120, 500,
        {
            columns: 1,
            columnGap: 0,
            height: 40,
            width: 174,
            align: 'center',
            continued: true

        }
    )
    .font('assets/enjelina.ttf')
    .fontSize(14)
    .fill('#021c27')
    .text('12/03/2022', 170, 510,);
const lineSize = 174; //horizontal hight
const signatureHeight = 500; //top to hight
doc.lineWidth(1);
doc.fillAndStroke('#021c27');
doc.strokeOpacity(0.2);
const startLine1 = 600;
const endLine1 = 600 + lineSize;
// Creates a line
doc
    .moveTo(startLine1, signatureHeight)
    .lineTo(endLine1, signatureHeight)
    .stroke();
// Evaluator info
doc
    .font('assets/geraldine.ttf')

    .fontSize(25)
    .fill('#021c27')
    .text(
        'Chhabiraj',
        startLine1,
        signatureHeight + 10,
        {
            columns: 1,
            columnGap: 0,
            height: 40,
            width: lineSize,
            align: 'center',

        }
    );
doc
    .fontSize(20)
    .fill('#021c27')
    .text(
        'Secretary',
        startLine1,
        signatureHeight + 30,
        {
            columns: 1,
            columnGap: 0,
            height: 40,
            width: lineSize,
            align: 'center',
        }
    );

doc.pipe(fs.createWriteStream('output.pdf'));
//   doc.rect(0, 0, doc.page.width, doc.page.height).fill('#fff');
doc.end();

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})
Previous
Next Post »