How do you adjust column alignment for individual columns (pdfmake)?

How do you adjust column alignment for individual columns (pdfmake)?

stycode7stycode7 Posts: 3Questions: 2Answers: 0

Hi, I'm using pdfmake with datatables, and I want to adjust data column alignments individually. For example, make column 1 be 'left' and column 2 be 'center'. Looking through the pdfmake documentation, I've only been able to figure out how to adjust columns overall with the 'defaultStyle' option. Anyone know if it's possible to have multiple column stylings?

                    extend: 'pdfHtml5',
                    text: 'Export',
                    orientation: 'landscape',                                     
                    pageSize: 'LEGAL',
                    customize: function ( doc ) {
                        doc.defaultStyle.fontSize = 7;
                        doc.styles.tableHeader.fontSize = 7;
                        doc.defaultStyle.alignment = 'center';

                        var currentPage = $('#report').DataTable().page.info().page;
                        var pages = $('#report').DataTable().page.info().pages;

                        var getTitle = $('title').text();
                        var parts = getTitle.split('|');

                        var title = {text: parts[0], alignment: 'left', fontSize: 20 };
                        var date = {text: 'DATE RANGE: ' + parts[1], alignment: 'left', fontSize: 20 };
                        var state = {text: parts[2], alignment: 'left', fontSize: 20 };

                        const getImg = document.querySelector('#Img');
                        var dataUrl = getDataUrl(getImg);
                        console.log(dataUrl);
                        doc['images'] = {
                            shcc: dataUrl
                        }
                        var objHeader = {};

                        objHeader['stack'] = [{image:"img",width: 1000, height: 150},title, date, state ];
                        
                        doc.content[0] = objHeader;
                                                doc['footer'] = function(currentPage, pages) { 
                            var cols = [];
                            cols[0] = {text: '', alignment: 'left', margin:[20] };
                            cols[1] = {text: 'Page ' + currentPage + ' of ' + pages, alignment: 'right', margin:[0,0,20] };
                            var objFooter = {};
                            objFooter['columns'] = cols;
                            return objFooter; 
                        };
                    }

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This might help, it's discussing that problem. If not, it'll be buried in the PDFmade docs somewhere, I'm afraid,

    Colin

  • stycode7stycode7 Posts: 3Questions: 2Answers: 0
    edited January 2022

    I don't think that will work in this case because I'm not defining the data in the 'body' element like that. It all comes from a datatable. I do have page numbers in the footer where I'm setting the alignment in that manner.

Sign In or Register to comment.