数据表和PDFmake [英] DataTables & PDFmake

查看:116
本文介绍了数据表和PDFmake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用DataTables导出功能,该功能可以导出为CSV,xlxs,pdf。现在,我当前的要求是导出自定义pdf(更改字体大小,颜色等)。在DataTable文档中指出,我们可以将其与PDFmake集成,但我无法做到这一点。

I'm trying to work with DataTables Export feature, where I am able to export as CSV, xlxs, pdf. Now my current requirement is to export a custom pdf (change the font size, color, etc.). In the DataTable documentation it states, that we can integrate it with PDFmake, which I am unable to do so.

如果有人可以提供集成/使用方式的帮助,带有DataTables的PDFmake真的很有帮助。

If anyone could please help in a way to integrate/use PDFmake with DataTables it would be really helpful.

预先感谢。

我正在初始化DataTables

I'm initialising the DataTables

var table = $('#Table').DataTable( {
  lengthChange: true,
  buttons: [
    'copyHtml5',
    {
      extend: 'csvHtml5',
      title:  'FileName'
    },
    {
      extend: 'excelHtml5',
      title:  'FileName'
    },
    {
      extend: 'pdfHtml5',
      orientation: 'landscape',
      title:  'FileName',
      //download: 'open',
      pageSize: 'A3'
    }
  ]
});

我拥有所需的所有必需的JS和CSS文件,如何在其中链接PDFMake?

I have all the necessary JS and CSS files required, how do I link the PDFMake in this?

推荐答案

声明数据表并更改字体时,可以访问PdfMake对象:

You can access the PdfMake object when you declare the DataTables and change the font like this:

window.pdfMake.fonts = {
        alef: {
            normal: 'Alef-Bold.ttf',
            bold: 'Alef-Bold.ttf',
            italics: 'Alef-Bold.ttf"',
            bolditalics: 'Alef-Bold.ttf',
        }
    };

此代码分配要使用的自定义字体Alef。我将其分配为vfs。

This code assigns the custom font Alef to be used. A font that I assigned as the vfs.

(请参见 https ://github.com/bpampuch/pdfmake/wiki/Custom-Fonts---客户端(如果您对此感兴趣)

(See https://github.com/bpampuch/pdfmake/wiki/Custom-Fonts---client-side if you are interested in how to make this)

对于其他自定义,您需要的是按钮中的自定义选项。

For other customizations what you need is the customize option in the Button.

参见此处:
https://datatables.net/reference/button/pdfHtml5

以下是如何在数据表中初始化新字体的示例

Here is an example of how to initialize the new font in the DataTable

 $("table").DataTable({
            buttons: [
                {
                    extend: 'pdf', className: 'btn green btn-outline',  text: 'Export PDF',
                    customize: function (doc) {
                        doc.defaultStyle = 
                            {
                                font: 'alef'
                            }

                          }
                       } 
                   ]
               });

这篇关于数据表和PDFmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆