Export PDF with 100% width

Export PDF with 100% width

cwdgcwdg Posts: 7Questions: 2Answers: 0

We are looking to upgrade to the newest version and the only thing holding us pack is the way the new version exports to pdf. The old version would set our tables to 100% width where as the new one does not. I have combed through all the api details and the only width call outs I can find are in reference to column width. Is there any to force 100% width on the table.

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    Unfortunately no. This is a limitation in the PDF library that Buttons uses that I hope will be addressed in a future update. Its author appears to be taking a break from development on it at the moment though.

    Allan

  • cwdgcwdg Posts: 7Questions: 2Answers: 0

    I suppose I could check the table for the row count and divide the width of the document by the number of rows to give me a fixed width for each of the columns.

  • cwdgcwdg Posts: 7Questions: 2Answers: 0

    I found that you simply need to add a width of '*' for each of the columns. I created a simple function in order to create an array based on the number of td tags and included a colspan check. I hope this helps those I have seen looking for a fix.

    var tbl = $('.dTable');
    var settings={};
    settings.buttons = [
        {
            extend:'pdfHtml5',
            text:'Export PDF',
            orientation:'landscape',
            customize : function(doc){
                var colCount = new Array();
                $(tbl).find('tbody tr:first-child td').each(function(){
                    if($(this).attr('colspan')){
                        for(var i=1;i<=$(this).attr('colspan');$i++){
                            colCount.push('*');
                        }
                    }else{ colCount.push('*'); }
                });
                doc.content[1].table.widths = colCount;
            }
        }
    ];
    $('.dTable').dataTable(settings);
    
  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin

    This is my outstanding question about this issue in the pdfmake repo. I'd like that to be resolved before including any changes in how Buttons uses the column widths.

    Having said that - thanks for posting your code - really useful!

    Allan

This discussion has been closed.