0

我必须将html元素转换为PDF,但我不想使用html2canvas,因为这个包首先转换html图像,然后再转换为pdf。这种方式对我的需求没有效率。

我使用了最新版本的 jspdf(1.5.3,表示支持内置 Unicode 和 utf-8 字符)和 jspdf-autotable。

一切都奏效了,除了损坏的波斯字符。我必须在最新版本的 jspdf 中对 Unicode 字符进行任何设置吗?我必须使用自定义字体?或内置支持Unicode字符的默认设置?

我阅读了有关此问题的所有文章并运行它,但我没有解决我的问题

4

1 回答 1

0

尝试使用html2pdf库正确导出 unicode 和波斯语/阿拉伯语字符。html代码必须在第一步转换为画布,然后再转换为pdf。

  function export_to_pdf() {
    // Get the element.
    var element = document.getElementById('root');

    // Generate the PDF.
    html2pdf().from(element).set({
      margin: 0,
      filename: 'test.pdf',
      html2canvas: { scale: 1},
      jsPDF: {orientation: 'portrait', unit: 'in', format: 'a4', compressPDF: true}
    }).save();
  }
于 2019-05-12T13:52:34.507 回答