将包含SVG的页面转换为PDF

时间:2018-10-01 10:38:47

标签: angular typescript svg jspdf

我正在尝试使用Angular 5将包含highchart.js图表​​的HTML页面导出为PDF。

我尝试了这种方法,但出现错误

var data = document.getElementById('contentToConvert');
      html2canvas(data).then(canvas => {
      var svg = document.getElementById('svg-container').innerHTML;

      if (svg)
        svg = svg.replace(/\r?\n|\r/g, '').trim();

      var createCanvas = document.createElement('canvas');
      var context = createCanvas.getContext('2d');
        console.log(createCanvas);

      context.clearRect(0, 0, createCanvas.width, createCanvas.height);
      canvas(canvas, svg);


      var imgData = createCanvas.toDataURL('image/png');

      // Generate PDF
      var doc = new jspdf('p', 'pt', 'a4');
      doc.addImage(imgData, 'PNG', 40, 40, 75, 75);
      doc.save('test.pdf');

这是错误:

addImage does not support files of type 'UNKNOWN', please ensure that a plugin for 'UNKNOWN' support is added

0 个答案:

没有答案