У меня проблема с генерацией PDF.
const puppeteer = require("puppeteer");
const fs = require("fs-extra");
const path = require("path");
const hbs = require("handlebars");
const data = require("./database.json");
const { v4 } = require("uuid");
const compile = async function(templateName, data) {
const filePath = path.join(process.cwd(), "views", `${templateName}.hbs`);
const html = await fs.readFile(filePath, "utf-8");
return hbs.compile(html)(data);
};
async function createPDF(data) {
try {
const pdfFileName = v4();
const browser = await puppeteer.launch();
const page = await browser.newPage();
console.log(data); <-- object
const content = await compile("index", data); <--- problem here
await page.setContent(content);
await page.emulateMedia("screen");
await page.pdf({
path: path.join(__dirname, `pdfs/${pdfFileName}.pdf`),
format: "A4",
printBackground: true
});
await browser.close();
} catch (error) {
console.log(error)
}
};
Все отлично работает. Я могу сгенерировать свой новый файл PDF, но по какой-то причине мой объект данных в шаблонах руля равен undefined
. Есть идеи как это решить?