如何在使用bootstrap导出html表时在pdf中包含标题

时间:2016-07-25 06:33:34

标签: bootstrapping

我正在尝试使用bootstrap(shieldUI-all.min.js)将html表数据导出为pdf。我完成了但我需要带有标题的pdf格式ie)标题在表的顶部。我不知道怎么做。

jQuery(function ($) {
            $("#export_supplier_pdf").click(function () {
        // parse the HTML table element having an id=exportTable
        var dataSource = shield.DataSource.create({
            data: "#table_supplier_master",
            schema: {
                type: "table",
                fields: {
                    CODE:  { type: String },
                    Name: { type: String },
                    ContactPerson: { type: String },
                }
            }
        });

        // when parsing is done, export the data to PDF
        dataSource.read().then(function (data) {
            var pdf = new shield.exp.PDFDocument({
                author: "GBLS",
                created: new Date()
            });

            pdf.addPage("a4", "portrait");

            pdf.table(
                50,
                50,
                data,
                [
                    { field: "CODE", title: "CODE", width: 200 },
                    { field: "Name", title: "Name", width: 200 },
                     { field: "ContactPerson", title: "ContactPerson", width: 200 }
                ],
                {
                    margins: {
                        top: 50,
                        left: 50
                    }
                }
            );

            pdf.saveAs({
                fileName: "Supplier_master"
            });
        });
    });
        });

或任何其他方式来实现同样的事情???

1 个答案:

答案 0 :(得分:2)

我相信目前没有简单的方法可以通过PDF选项实现这一目标: http://www.shieldui.com/documentation/grid/javascript/api/settings/exportOptions/pdf 另一种选择是简单地将所需数据添加到网格本身,以便将其导出到PDF文档。