使用.text方法向标题添加文本 [英] Add text to header with .text method

查看:122
本文介绍了使用.text方法向标题添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何像jspdf中的标头一样重复文本.如果我添加这样的文本(jspdf.text(x,y,'test'),那么它只会出现在首页上!

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!

注意:我已经在此文档上创建了标头,但这是使用html中的<header>标记完成的.我想补充一下.我必须以这种方式添加文本,以解决jspdf具有的对齐问题.

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

推荐答案

我最终破解了整个jspdf.debug.js代码,并向其中添加了大量的if语句,以解决我的表呈现方式问题.以下是一些示例:

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);

我遇到一个问题,一旦我向表头添加表,文档就会重复我的主数据表的表头中的最后一个表头,该表具有100条或更多的记录(因此它重复了多个页面,而第2页和第2页以上是错误的)标题)

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);
            }
        }

-我将其添加到构造标题行的for循环中(我的主表有5列)

--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;
    }
}

-在tabletojson函数中,我将其更改为手动设置表

--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还在**** TABLE RENDERING ****部分中手动更改了表:

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

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

这篇关于使用.text方法向标题添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆