PDF and Print Buttons - Footer on each page

PDF and Print Buttons - Footer on each page

mpiettegssmpiettegss Posts: 1Questions: 1Answers: 0

I have looked and looked and was wondering if someone could assist me. I need to add a disclaimer on each page of my document that is created with the PRINT and PDF buttons of the datatables on my site.I am using tablepress shortcodes to pull my data in, so the table is already initialised and when I add the following code, I get the error "Datatables warning(table id = 'example'): cannot reinitialise data table."

Where does this code go? I am using the PRINT and PDFhtml5 buttons to save my tables, but don't know where to add the script to get page footer on each page of my document. I want a similar effect as this Custom PDF button: https://codepen.io/RedJokingInn/pen/XMVoXL

$('#myTable').DataTable( {
                "buttons": [
                {
                    text: 'Custom PDF',
                    extend: 'pdfHtml5',
                    filename: 'dt_custom_pdf',
                    orientation: 'landscape', 
                    pageSize: 'letter',
                    exportOptions: {
                        columns: ':visible',
                        search: 'applied',
                        order: 'applied'    },
                                     customize: function (doc) {
                        doc['header']=(function() {
                            return {
                                columns: [
                                    {
                                        image: logo,
                                        width: 24
                                    },
                                    {
                                        alignment: 'left',
                                        text: 'dataTables',
                                        fontSize: 18,
                                    },
                                    {
                                        alignment: 'right',
                                        fontSize: 14,
                                        text: 'Custom PDF'
                                    }
                                ],
                                margin: 20
                            }
                        });
                        // Create a footer object with 2 columns
                        // Left side: report creation date
                        // Right side: current page and total pages
                        doc['footer']=(function(page, pages) {
                            return {
                                columns: [
                                    {
                                        alignment: 'left',
                                        text: ['LEFT TEXT']
                                    },
                                    {
                                        alignment: 'right',
                                        text: ["RIGHT TEXT]
                                    }
                                ],
                                margin: 20
                            }
                        });
 } );
}]
    });

I've tried in the min.js files for each type of button and then the regular .js files, but no luck. Any help or guidance would be appreciated.

Thanks!
Michelle

Answers

  • colincolin Posts: 74Questions: 0Answers: 14

    Hi Michelle,

    You can tinker with the CSS to do customer headers and footers - see this stackoverflow discussion. It doesn't look easy, so it would be worth chatting to TablePress to see if they can do something. Likewise, the error you mentioned, that's deep in the TablePress code.

    If can work out how to do it with CSS, you could create a custom print button on the table with button().add().

    Not the best answer, but hope that helps,

    Cheers,

    Colin

Sign In or Register to comment.