首页 文章

如何在jspdf autoTable中的beforePageContent中使用lineBreak

提问于
浏览
2

我正在我的程序中使用 overFlow : linebreak . 它工作正常这是我的代码,

styles: {
                		  fillStyle: 'DF',
                	      overflow: 'linebreak',
                	      columnWidth: 110,
                	      lineWidth: 2,
                	      lineColor: [85, 51, 27]
                           
                	    }

但这并没有反映在 beforePageContent 里面,这是代码,

beforePageContent: function(data) {
                	    	doc.setFontSize(12);
                	    	doc.setFont("courier");
                	    	doc.text("Process Name :",20 ,15);
                	    	doc.setFontStyle('bold');
                	    	//doc.overflow('linebreak');
                	        doc.setFontStyle('normal');
                       doc.text("Description :"+sampData, 20, 30);
                	        
                	        
                	    },

那我怎么能在 beforePageContent 块中使用 lineBreak .

1 回答

  • 3

    overflow: linebreak; 样式仅适用于 jspdf-autotable . 在钩子(例如beforePageContent)中,您使用纯jspdf并且需要使用jspdf方法 . 有两个功能你可能会有所帮助 . 第一个是 doc.getStringUnitWidth("hello") ,第二个是 doc.splitTextToSize("A longer title that might be split", 50) .

    Example 1:

    var strArr = doc.splitTextToSize("A longer title that might be split", 50)
    doc.text(strArr, 50, 50);
    

    Example 2:

    var str = "A longer title that /n is split";
    doc.text(str, 50, 50);
    

相关问题