-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add pdf-lib dependency for generating certificates, Add COMPLE…
…TE status
- Loading branch information
1 parent
d0e4843
commit a9d954c
Showing
11 changed files
with
129 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { PDFDocument, rgb } from 'pdf-lib' | ||
import fs from 'fs' | ||
|
||
export async function generateCertificate( | ||
menteeName: string, | ||
sourcePdfPath: string, | ||
outputPath: string | ||
): Promise<string> { | ||
try { | ||
const existingPdfBytes = fs.readFileSync(sourcePdfPath) | ||
const pdfDoc = await PDFDocument.load(existingPdfBytes) | ||
const page = pdfDoc.getPage(0) | ||
const fontSize = 24 | ||
const datezFontSize = 18 | ||
|
||
page.drawText(menteeName, { | ||
x: 66, | ||
y: page.getHeight() - 220, | ||
size: fontSize, | ||
color: rgb(0, 0, 0) | ||
}) | ||
|
||
const issueDate = new Date().toLocaleDateString() | ||
|
||
page.drawText(issueDate, { | ||
x: 160, | ||
y: page.getHeight() - 476, | ||
size: datezFontSize, | ||
color: rgb(0, 0, 0) | ||
}) | ||
|
||
const pdfBytes = await pdfDoc.save() | ||
|
||
fs.writeFileSync(outputPath, pdfBytes) | ||
return outputPath | ||
} catch (error) { | ||
console.error('Failed to modify the PDF:', error) | ||
throw error | ||
} | ||
} |
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
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
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
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
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