数据表 &PDF制作 [英] DataTables & PDFmake

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

问题描述

我正在尝试使用 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.

如果有人可以帮助将 PDFmake 与 DataTables 集成/使用,那将非常有帮助.

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

提前致谢.

我正在初始化数据表

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?

推荐答案

当您声明 DataTables 并更改字体时,您可以访问 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---client-side 如果你对如何制作这个感兴趣)

(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

这里是如何在DataTable中初始化新字体的例子

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'
                            }

                          }
                       } 
                   ]
               });

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

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