HTML to PDF (by javascript) how can I add css or table?

后端 未结 2 1309
伪装坚强ぢ
伪装坚强ぢ 2021-02-10 06:58

In a project I have convert html file into pdf,than it\'s working fine.But this output not showing css design.Now I need a suggestion how can I add css design with this pdf file

相关标签:
2条回答
  • 2021-02-10 07:29

    Ok after lots of try I have solved it.Especial thanks for mihaidp,Here the code I have solve table row problem

    $('#cmd').click(function () {
            var table = tableToJson($('#StudentInfoListTable').get(0))
            var doc = new jsPDF('p', 'pt', 'a4', true);
            doc.cellInitialize();
            $.each(table, function (i, row){
                    doc.setFontSize(10);
    
                    $.each(row, function (j, cell){
                    if(j=='name')
                    {
                        doc.cell(10, 50,100, 30, cell, i);
                    }
                    else if(j=='email')
                    {
                        doc.cell(10, 50,130, 30, cell, i);
                    }
                    else if(j=='track')
                    {
                        doc.cell(10, 50,40, 30, cell, i);
                    }
                    else if(j=='s.s.croll')
                    {
                        doc.cell(10, 50,51, 30, cell, i);
                    }
                    else if(j=='h.s.croll')
                    {
                        doc.cell(10, 50,51, 30, cell, i);
                    }
                    else 
                    {
                        doc.cell(10, 50,70, 30, cell, i);  
                    }
                })
            }) 
    

    After solve here the output enter image description here

    0 讨论(0)
  • 2021-02-10 07:29

    Hmm! I think this post can give you all you need, with mPDF: how to add css file in mpdf

    With jsPDF I only know about the hard way: http://mrrio.github.io/jsPDF/doc/symbols/jsPDF.html (See Method Summary).

    Hope it helps!

    0 讨论(0)
提交回复
热议问题