Saravana Kumar
Saravana Kumar

Reputation: 179

How to use lineBreak inside the beforePageContent in jspdf autoTable

i'm using overFlow : linebreak in my program .And it work's fine this is my code ,

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

But that doesn't reflect inside the beforePageContent , Here is that code ,

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

So how can i use lineBreak inside my beforePageContent block .

Upvotes: 4

Views: 19064

Answers (1)

Simon Bengtsson
Simon Bengtsson

Reputation: 8151

The overflow: linebreak; style is only for jspdf-autotable. In the hooks you are using pure jspdf and need to use jspdf methods. There are two functions that you are probably going to be helpful. The first one is doc.getStringUnitWidth("hello") and the second is 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);

Upvotes: 11

Related Questions