jsPDF添加base64字符串

时间:2018-10-10 07:28:40

标签: javascript angular typescript jspdf

我正在尝试将Blob(type: 'application/pdf')转换为base64字符串,并从该字符串生成pdf(with jsPDF)以添加名称。我的代码如下:

writeToBlob(blob: Blob) {
    var base64;
    var name = "Peter Pan";
    var reader = new FileReader();
    reader.readAsDataURL(blob);
    reader.onloadend = function () {
      base64 = reader.result;
      var doc = new jsPDF;
      doc.addImage(base64, 0, 0, 210, 296);
      doc.text(100, 31, name);
      doc.save('test.pdf');
    }
  }

我的问题是我遇到了错误"addImage does not support files of type 'UNKNOWN', please ensure that a plugin for 'UNKNOWN' support is added." base64的第一个字符如下所示:data:application/pdf;base64,JVBERi0xLjcNCiW...

0 个答案:

没有答案