Add puppeteer to convert to pdf
Some checks failed
Build / Build_And_Publish (push) Failing after 33s
Some checks failed
Build / Build_And_Publish (push) Failing after 33s
This commit is contained in:
35
build.js
35
build.js
@@ -1,20 +1,37 @@
|
||||
const ejs = require('ejs');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const ejs = require("ejs");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const puppeteer = require("puppeteer");
|
||||
|
||||
// File paths
|
||||
const dataPath = path.join(__dirname, 'content.json');
|
||||
const templatePath = path.join(__dirname, 'template.ejs');
|
||||
const outputPath = path.join(__dirname, 'generated_resume.html');
|
||||
const dataPath = path.join(__dirname, "content.json");
|
||||
const templatePath = path.join(__dirname, "template.ejs");
|
||||
const outputPath = path.join(__dirname, "generated_resume.html");
|
||||
|
||||
// Read data and template
|
||||
const jsonData = JSON.parse(fs.readFileSync(dataPath, 'utf-8'));
|
||||
const template = fs.readFileSync(templatePath, 'utf-8');
|
||||
const jsonData = JSON.parse(fs.readFileSync(dataPath, "utf-8"));
|
||||
const template = fs.readFileSync(templatePath, "utf-8");
|
||||
|
||||
// Render HTML
|
||||
const html = ejs.render(template, jsonData);
|
||||
|
||||
// Write the output
|
||||
fs.writeFileSync(outputPath, html, 'utf-8');
|
||||
fs.writeFileSync(outputPath, html, "utf-8");
|
||||
|
||||
console.log(`Successfully generated resume at ${outputPath}`);
|
||||
|
||||
async function generatePdf(htmlPath) {
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
await page.goto(`file://${htmlPath}`, {
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
// Saves the PDF to hn.pdf.
|
||||
await page.pdf({
|
||||
path: "resume.pdf",
|
||||
});
|
||||
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
generatePdf(outputPath).then(() => console.log("Generated PDF version"));
|
||||
|
||||
Reference in New Issue
Block a user