0

我在 ReactJS 应用程序中运行 pdf-autotable v2.3.2 和 jspdf v1.3.3。我没有更改任何代码,但以前显示在新 Chrome 选项卡中的 PDF(并且看起来很漂亮,顺便说一句)现在不再显示。

The tab opens with the title Untitled, a URL like data:application/pdf;base64,JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9...(thousands of characters)...Ci9CaXRzUGVyQ29tcG9uZW50IDgKL0ZpbHRlciAvRENURGVjb2RlCi9MZW5ndGggNDAyMj4+CnN0cmVhbQr/2P/hABhFeGlmAABJSSoACAAAAAAAAAAAAAAA/+wAEUR1Y2t5AAEABAAAADwAAP/hAzFodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD%E2% 80%A6%E2%80%A6 和一个空网页。

我的 pdf/autotable 代码是:

  printGrid() {
    let doc = new jsPDF('landscape');
    const totalPagesExp = "{total_pages_count_string}";

    let pageContent = function (data) {

        // HEADER
        doc.setFontSize(20);
        doc.setTextColor(40);
        doc.setFontStyle('normal');
        doc.addImage(getBase64ImgGlobal(), 'JPEG', data.settings.margin.left, 15, 10, 10);
        doc.text(fullReportName, data.settings.margin.left + 15, 22);

        // FOOTER
        var str = "Page " + data.pageCount;
        if (typeof doc.putTotalPages === 'function') {
            str = str + " of " + totalPagesExp;
        }
        doc.setFontSize(10);
        doc.text(str, data.settings.margin.left, doc.internal.pageSize.height - 10);
    };

    let _this = this;

    doc.autoTable(this.getPdfColumns(), this.getPdfData(), {
        addPageContent: pageContent,
        margin: {top: 30},
        createdHeaderCell: function(cell, data) { _this.alignCol(cell, data) },
        createdCell: function(cell, data) { _this.alignCol(cell, data) }
    });

    if (typeof doc.putTotalPages === 'function') {
        doc.putTotalPages(totalPagesExp);
    }

    doc.setProperties({
      title: fullReportName
    });

    doc.output('dataurlnewwindow');
  };

然后我注释掉了我自己的所有代码并粘贴在你最简单的例子中:

var columns = ["ID", "Country", "Rank", "Capital"];
var data = [
    [1, "Denmark", 7.526, "Copenhagen"],
    [2, "Switzerland",  7.509, "Bern"],
    [3, "Iceland", 7.501, "Reykjavík"],
    [4, "Norway", 7.498, "Oslo"],
    [5, "Finland", 7.413, "Helsinki"]
];

var doc = new jsPDF();
doc.autoTable(columns, data);
doc.output("dataurlnewwindow");

同样的事情也发生了。请帮忙。

4

1 回答 1

0

尝试使用doc.save()而不是doc.output()

于 2018-08-04T15:47:50.970 回答