Add text to header with .text method

£可爱£侵袭症+ 提交于 2019-12-12 05:13:48

问题


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 header on this doc but that's done in the html with the <header> tag. I want to append to that sort of. I have to add the text this way as a work around for alignment issues jspdf has.

var pdf = new jsPDF('p', 'pt', 'letter');
pdf.rect(430, 20, 125, 50);
pdf.text('Order', 430, 35);
pdf.autoTableHtmlToJson
source = $('#content')[0]; //table Id

回答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 manually
var 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 me
        this.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;
            }


来源:https://stackoverflow.com/questions/36347346/add-text-to-header-with-text-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!