【问题标题】:Tabulator combine multiple tables in a single pdf制表器将多个表格合并到一个 pdf 中
【发布时间】:2020-07-24 23:31:39
【问题描述】:

我正在使用http://tabulator.info/ 在单个 HTML 文档页面上生成多个表格。

当我通过按钮触发 pdf 下载时,应该会生成一个 pdf 文档,其中包含文档中的表格。 到目前为止,下载单个表格是可行的,但我不知道如何在 jsPDF 完成之前向文档中添加更多表格。

到目前为止,我尝试的是在触发table1 的下载时,我在documentProcessing 函数中抓取了lastTable1 = doc.lastAutoTable 对象。计划是将其传递到table2.download() 并通过autoTable: function(doc){doc.autoTable(lastTable1)} 添加。

虽然我确实用这种方法抓取了一个对象,但我不能用它来重建自动表对象(例如,doc.autoTable(lastTable1) 不会再次生成同一个表)。

我准备了一个简单的jsfiddle,我在其中生成了两个表格和一个下载按钮。只是为了说明 autotable 对象的重建不起作用,我在创建 pdf 之前再次将其添加到 doc

【问题讨论】:

    标签: javascript jspdf tabulator jspdf-autotable


    【解决方案1】:

    制表器没有内置的方法来执行此操作。

    但好消息是添加一些东西来自己处理应该很容易。

    This Issue 展示了如何使用 jsPDF 将 PDF 合并到同一个文档中。

    您可以使用制表符内置的 downloadReady 回调来拦截从每个表创建的 PDF 文件,然后使用上述问题中概述的方法将它们组合起来

    var table = new Tabulator("#example-table", {
        downloadReady:function(fileContents, blob){
            //fileContents - the unencoded contents of the file
            //blob - the blob object for the download
    
            mergeWithPreviousPDFs(blob); // call a function based on the previous issue that merges the new PDF with the previous PDF's
    
            return blob; //must return a blob to proceed with the download, return false to abort download
        }
    });
    

    如果你从这个回调中返回false,下载将不会被触发,所以你可以拦截除决赛桌之外的所有PDF输出以阻止下载然后返回最后一个表的组合输出以触发下载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-05
      • 2013-03-03
      • 2019-06-27
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多