requirejs,datatables和pdfmake - 在虚拟文件系统中找不到未捕获的文件'Roboto-Regular.ttf'

问题描述 投票:1回答:1

这是我的代码。

requirejs.config({
 "paths":{
'pdfmake': '//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min',
},

"shim": {
'pdfmake': {
            deps: ["//cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"]
        },
}

});

在数据表中 - https://datatables.net/extensions/buttons/examples/html5/pdfMessage.html

requirejs(['pdfmake'],function(){
 $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            {
                extend: 'pdfHtml5',
                messageTop: 'PDF created by PDFMake with Buttons for DataTables.'
            }
        ]
    } );

});

在检查中我看到文件已加载,但是当我创建pdf - get

Uncaught File 'Roboto-Regular.ttf' not found in virtual file system

更新1我尝试创建实例但有一些错误... https://jsfiddle.net/9gkat5dc/13/

无法加载'https://cdn.datatables.net/buttons/1.4.2/swf/flashExport.swf'作为插件,因为插件加载到的框架是沙箱。

datatables requirejs pdfmake
1个回答
0
投票
"shim": {
    "vfs_fonts": ["pdfmake"]
},

应该解决这个问题(在我的安装中确实如此)。 vfs_fonts需要加载AFTER pdfmake,而不是之前。据我了解你的配置,你的pdfmake依赖于vfs_fonts。

编辑:我看到你将URL添加到vfs_fonts作为dep。我在路径数组中完成了这个。

© www.soinside.com 2019 - 2024. All rights reserved.