使用jsPDF生成的PDF文件未在Microsoft Edge上显示

时间:2019-11-21 07:34:00

标签: angular microsoft-edge jspdf

我目前正在从事一个项目,我必须在其中使用jsPDF生成有关单击按钮的报告。该代码在Google Chrome和Mozilla Firefox上运行良好,但在Microsoft Edge上不起作用。 PDF文档在后台加载到iframe中,但页面为白色和空白。谁能建议一种在Microsoft Edge中正确显示PDF的解决方案?

注意:我无法共享代码,因为它会导致版权侵权。对不起。另外,当我单击按钮时,调试器会显示 no such interface supported 错误。

谢谢。

这是我创建的示例代码,用于演示该问题:

import { Component, OnInit } from '@angular/core';
import * as data from '../dummy.json';
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';

@Component({
  selector: 'app-create-pdf',
  templateUrl: './create-pdf.component.html',
  styleUrls: ['./create-pdf.component.css']
})
export class CreatePDFComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    debugger;
    var columns = [
      {title: "ID", dataKey: "id"},
      {title: "Name", dataKey: "name"}, 
      {title: "Country", dataKey: "country"}, 
  ];

  var rows = [
      {"id": 1, "name": "Shaw", "country": "Tanzania"},
      {"id": 2, "name": "Nelson", "country": "Kazakhstan"},
      {"id": 3, "name": "Garcia", "country": "Madagascar"},
  ];

  var doc = new jsPDF('p', 'pt');
  doc.autoTable(columns, rows, {
      styles: {fillColor: [100, 255, 255]},
      columnStyles: {
        id: {fillColor: 255}
      },
      margin: {top: 60},
      beforePageContent: function(data) {
        doc.text("Header", 40, 30);
      }
  });
      let blob = doc.output("dataurlnewwindow");
      var newWindow = window.open(URL.createObjectURL(blob));
      newWindow.document.write('<title>My PDF File Title</title>');    
    }   
  }

0 个答案:

没有答案