Datatables PDF export with custom table

Datatables PDF export with custom table

davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0
edited August 2020 in Free community support

I would like to make a custom PDF so that I can dictate where the rows and columns are. I think I have a jist of what needs to be done but just need some help getting the data.

  {
            extend: 'pdfHtml5',
            text: 'PDF',
            orientation: 'landscape',
            pageSize: 'LEGAL',
            customize: function (doc) {
                                    //Remove the title created by datatTables
                                    doc.content.splice(0,1);
                                    var now = new Date();
                                    var jsDate = now.getDate()+'-'+(now.getMonth()+1)+'-'+now.getFullYear();
                                    doc.pageMargins = [20,60,20,30];
                                    doc.defaultStyle.fontSize = 8;
                                    doc.styles.tableHeader.fontSize = 8;

                                    doc['header']=(function() {
                                        return {
                                            columns: [

                                                {
                                                    alignment: 'left',
                                                    italics: true,
                                                    text: 'Customer Table ' + now,
                                                    fontSize: 18,
                                                    margin: [10,0]
                                                },
                                                {
                                                    alignment: 'right',
                                                    fontSize: 14,
                                                    text: 'Region Orders'
                                                }
                                            ],
                                            margin: 20
                                        }
                                    });

                                    doc['footer']=(function(page, pages) {
                                        return {
                                            columns: [
                                                {
                                                    alignment: 'left',
                                                    text: ['Created on: ', { text: jsDate.toString() }]
                                                },
                                                {
                                                    alignment: 'right',
                                                    text: ['page ', { text: page.toString() },  ' of ', { text: pages.toString() }]
                                                }
                                            ],
                                            margin: 20
                                        }
                                    });

                                    var objLayout = {};
                                    objLayout['hLineWidth'] = function(i) { return .5; };
                                    objLayout['vLineWidth'] = function(i) { return .5; };
                                    objLayout['hLineColor'] = function(i) { return '#aaa'; };
                                    objLayout['vLineColor'] = function(i) { return '#aaa'; };
                                    objLayout['paddingLeft'] = function(i) { return 4; };
                                    objLayout['paddingRight'] = function(i) { return 4; };
                                    doc.content[0].layout = objLayout;
                            }
          }

How can I grab the row data and insert it into a custom table here?

IE:

Customer
Cust Name: col2 Item Name: col4
Item Qty: col5
Total: col10

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    There are some examples on this thread about how to parse the document. I suspect it won't be easy - it might be worth asking on the PDFmake forum perhaps.

    Colin

This discussion has been closed.