首页 > 解决方案 > 打印列表时 pdfMake 和 html-to-pdfmake 的问题

问题描述

我正在尝试从查询到数据库生成 pdf,其中信息具有 HTML 代码,如列表。<p>DDDD</p><ol><li>asdasdas</li><li>asdasdasd</li><li>asdasdasd</li></ol><ul> <li> sdasdasd </li> </ul>

安装pdfmakeand后html-to-pdfmake,我将它们导入到我的 component.ts

const pdfMake = require('node_modules/pdfmake/build/pdfmake')
const pdfFonts = require('node_modules/pdfmake/build/vfs_fonts')
pdfMake.vfs = pdfFonts.pdfMake.vfs
const htmlToPdfmake = require('html-to-pdfmake')

在某些时候我发送调用它生成的方法创建我的pdf

savePDF() {
    console.log(this.reConsulta)

    const documentDefinition = {
      pageSize: 'A5',
      // by default we use portrait, you can change it to landscape if you wish
      pageOrientation: 'landscape',
      // [left, top, right, bottom] or [horizontal, vertical] or just a number for equal margins
      pageMargins: [5, 100, 5, 10],

      content: [
        { text: htmlToPdfmake(this.reConsulta.medicamentos) },
        { text: htmlToPdfmake(this.reConsulta.metodo), absolutePosition: { x: 320, y: 100 } },
      ],
    }

    pdfMake.createPdf(documentDefinition).open()
  }

此时this.reConsulta.medicamentos有前一个列表的值<p>DDDD</p><ol><li>asdasdas</li><li>asdasdasd</li> <li> asdasdasd </li> </ol><ul><li>sdasdasd</li> </ul>

但是当创建 pdf 时,列表不会显示,但是其他 html 标签如<b> </b> <i> </i>格式化没有问题。

标签: htmlangularhtml-to-pdfpdfmake

解决方案


推荐阅读