1

下面的代码呈现以下 PDF:Link to PDF on Google Docs。(我不被允许在这篇文章中粘贴图片)

每首歌曲都有歌曲标题和和弦进行。我正在寻找的是为每首歌曲/和弦单元格设置一行。在示例中,我在代码中对最后一首歌曲进行了硬编码,以显示它应该呈现的样子。每首歌都应该有自己的表格行。我已经研究了几个小时,但无法弄清楚......希望这是一个简单的解决方案,我只是错过了一些非常明显的东西。

谢谢你的帮助。

    //Fired when SET header clicked to generate PDF
    $scope.openPDF = function (SetName, setSongs) {                       
        songTitles = [];
        songChords = [];

        angular.forEach(setSongs, function(value, key) {            
            songTitles.push({ text: value.Title, style: 'tableHeader'});
            songChords.push({ text: value.Chords, style: 'tableHeader'});
        });

        var docDefinition = 
        {       
           pageOrientation: 'landscape',

           content: [
             { text: 'SET 01', style: 'firstLine'},
             { text: SetName, style: 'secondLine' },                 
                {  
                    table: 
                    {
                        headerRows: 0,                            
                        body: 
                        [                       
                          [songTitles, songChords],['American Girl', 'D - E - G - A']
                        ]
                    }
                }
           ],

           styles: {
             firstLine: {
               fontSize: 32,
               bold: true,
               alignment: 'center'
             },
             secondLine: {
               fontSize: 15,
               bold: true,
               alignment: 'center'
             },
           }

        };//End docDefinition

        //Generate PDF
        pdfMake.createPdf(docDefinition).open();

    }; //END Function  
4

1 回答 1

2

整理出来......发布解决方案以防它帮助某人。

使用以下函数创建的 PDF 链接:https ://drive.google.com/open?id=0B9COonOvl5koR09aNkRZUHpPczA

所有数据都是从 MySQL 数据库中提取的……所以有一个包含各种属性(标题、艺术家、主和弦结构等)的歌曲表 - 然后是一个包含三个集合列表的集合表。

    //Fired when SET header clicked to generate PDF
    $scope.openPDF = function (setList, setSongs, setNumber) {                       
        songRows = [];

        angular.forEach(setSongs, function(value, key) {            
            songRows.push({Title: value.Title, Chords: value.Chords, WhoStarts: value.WhoStarts});                
        });

        var items = songRows.map(function(item) {
         return [(100 + songRows.indexOf(item) + 1).toString().slice(-2) + '.', item.Title, item.Chords, item.WhoStarts];
        });

        var docDefinition = 
        {       
           pageOrientation: 'landscape',

           content: 
           [
                { text: setNumber, style: 'firstLine'},
                { text: setList.EventDate + ' - ' + setList.SetName + ' @ ' + setList.Venue + '\n\n', style: 'secondLine' },                 
                {  
                    style: 'songRow',
                    table: 
                    {                                                   
                      body: 
                      [
                        [                             
                          { text: '------' },
                          { text: '--------------------------------------' },
                          { text: '--------------------------------------' },
                          { text: '--------------------------------------' },  
                        ]
                      ].concat(items)                         
                    }
                }
           ],

           styles: {
             firstLine: {
               fontSize: 32,
               bold: true,
               alignment: 'center'
             },
             secondLine: {
               fontSize: 15,
               bold: true,
               alignment: 'center'
             },
             songRow: {
               fontSize: 18,
               bold: true,
               alignment: 'center',                   
             },
           }

        };//End docDefinition

        //Generate PDF
        pdfMake.createPdf(docDefinition).open();
    } //END Generate PDF Function  
于 2016-06-07T13:46:05.963 回答