首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在节点js中将html表单转换为pdf?

问在节点js中将html表单转换为pdf?
EN

Stack Overflow用户
提问于 2020-09-17 20:23:47
回答 1查看 90关注 0票数 0

我创建了一个将HTML文件转换为pdf的类。下面是代码

代码语言:javascript
复制
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。

请告诉我怎么做?

EN

回答 1

Stack Overflow用户

发布于 2020-09-17 20:31:34

你试过jsPDF吗?根据他们的网站,jsPDF是一个领先的HTML5客户端解决方案,用于生成PDF。完美的活动门票,报告和证书。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63937967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档