Skip to content Skip to sidebar Skip to footer

Add Text To Header With .text Method

Can someone tell me how to get text to repeat like header does in jspdf. if I add text like this (jspdf.text(x,y,'test') it's only going on first page! note: I already have a he

Solution 1:

I ended up cracking the entire jspdf.debug.js code and adding tons of if statements to it in order to solve my issues with how it renders tables. a few examples below:

--the cell height was huge for the headers

if (printHeaders) {
//changed by me on 4/5/16 to calculate lineheight manuallyvar lineHeight = 20;//this.calculateLineHeight(headerNames, columnWidths, headerPrompts.length?headerPrompts:headerNames);

I had a problem that once I was adding tables to my header, the doc was repeating the last header from the header for my MAIN DATA table that had 100 records or more (so it repeated multiple pages and pages 2+ had wrong header)

// Store the table header config  //changed by methis.setTableHeaderRow(tableHeaderConfigs);
        if (tableHeaderConfigsMain != undefined) {
            if (tableHeaderConfigsMain.length > 0) {
                this.setTableHeaderRowMain(tableHeaderConfigsMain);
            }
        }

--I added this to the for loop that constructs the header row (my main table had 5 columns)

        if (headerNames.length == 5) {
            tableHeaderConfigsMain.push([x, y, columnWidths[header], lineHeight, String(headerPrompts.length ? headerPrompts[i] : header)]);
}   

--added this to the print header row function

if (this.tableHeaderRowMain != undefined && new_page) {
    if (this.tableHeaderRowMain.length > 0) {
        this.tableHeaderRow = this.tableHeaderRowMain;
    }
}

--in the tabletojson function i changed this to manually set up my tables

if(table.id=='rightAlignTable'){
                headers[i] = {
                    name : cell.textContent.toLowerCase().replace(/\s+/g, ''),
                    prompt:'Date', //cell.textContent.replace(/\r?\n/g, ''),
                    width : 100 //(cell.clientWidth / table_with) * renderer.pdf.internal.pageSize.width

                };
                headers[1] = {
                    name : cell.textContent.toLowerCase().replace(/\s+/g, ''),
                    prompt:'PO #',//cell.textContent.replace(/\r?\n/g, ''),
                    width : 100 //(cell.clientWidth / table_with) * renderer.pdf.internal.pageSize.width
                };
            }

--i also manually changed tables here in the ****TABLE RENDERING**** section:

if (cn.id === "rightAlignTable") {
                x = 425;
                y = 25;
            }

Post a Comment for "Add Text To Header With .text Method"