我创建了一个将HTML文件转换为pdf的类。下面是代码
class Invoice {
async html() {
try {
const data = {
your: 'data'
}
console.log("Current directory:", __dirname);
const templatePath = Path.resolve('index.html')
console.log(templatePath)
const content = await ReadFile(templatePath, 'utf8')
// compile and render the template with handlebars
const template = Handlebars.compile(content)
return template(data)
} catch (error) {
throw new Error('Cannot create invoice HTML template.')
}
}
async pdf() {
const html = await this.html()
console.log(html)
const browser = await Puppeteer.launch()
const page = await browser.newPage()
await page.setContent(html)
return page.pdf()
}
}但是这读取了一个位于磁盘上的HTML文件。但我想在HTML文件中创建html表单的pdf。
请告诉我怎么做?
发布于 2020-09-17 20:31:34
你试过jsPDF吗?根据他们的网站,jsPDF是一个领先的HTML5客户端解决方案,用于生成PDF。完美的活动门票,报告和证书。
https://stackoverflow.com/questions/63937967
复制相似问题