question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jsPDF autoTable columnWidth wrap cuts table off

See original GitHub issue

I am using jsPDF to generate a PDF from an HTML table and jsPDF is great, expect I am having one issue, when I try to wrap the columnWidth, my table gets cut off 😦

var doc = new jsPDF('l', 'mm', "a0");
var tbl = $('#cost-matrix-table').clone();
tbl.find('tr:nth-child(1)').remove();
tbl.find('tr:nth-child(1)').remove();
tbl.find('tr:nth-child(2)').remove();
var res = doc.autoTableHtmlToJson(tbl.get(0));

doc.autoTable(res.columns, res.data, {
    startY: 40,
    margin: {
        top: 40
    },
    addPageContent: function (data) {
        doc.setFontSize(28);
        doc.setTextColor(0);
        doc.setFontStyle('bold');
        doc.text("Cost Matrix " + $("#dropdown").val(), 500, 30);
    },
    styles: {
        fontSize: 20,
        overflow: 'linebreak',
        columnWidth: 'wrap',
    },
    theme: 'grid'
});

doc.save("Report.pdf");

Is there a solution for this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Tichjucommented, Feb 12, 2018
doc.autoTable(columns, JSON.parse(rows), {
        margin: {horizontal: 5},
        bodyStyles: {valign: 'middle'},
        styles: {overflow: 'linebreak', columnWidth:'wrap'},
        theme: 'plain',
        columnStyles: {
            text: {
                columnWidth: 'wrap'
            },
            columnName1: {
                columnWidth: 45,
                fontStyle: 'bold',
                textColor: 240                
            },
            description: {
                columnWidth: 107
            },
            columnName2: {
                columnWidth: 45
            },
            columnName3: {
                columnWidth: 45
            },
            columnName4: {
                columnWidth: 45
            }
        }
    });

The code looks for numbers, it was enough to remove the ‘’. ‘107’ → 107

0reactions
laviranacommented, Jul 6, 2020

how I can set the single row height according to the image height in the table?

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsPDF autoTable columnWidth wrap cuts table off
Replace your autotable creation part into below code doc.autoTable(res.columns, res.data, { startY: 40, margin: { top: 40 }, addPageContent: ...
Read more >
jsPDF autoTable columnWidth wrap cuts table off
I am using jsPDF to generate a PDF from an HTML table and jsPDF is great, expect I am having one issue, when...
Read more >
Developers - jsPDF autoTable columnWidth wrap cuts table off
I'm trying do to a pagination with jspdf - autotable . But i dont know how to get total number of pages ....
Read more >
Jquery – How to fit a jspdf autotable in a pdf document
jqueryjspdf. I am trying to fit a table in a pdf using jspdf autotable plugin but for some reason the text in the...
Read more >
How to fit the field text to the column width of a... - ServiceNow
We have a UI Page which creates a PDF document. The PDF contains a table which populates data from the table within Service...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found