How to use lineBreak inside the beforePageContent in jspdf autoTable

Saravana Kumar picture Saravana Kumar · Aug 9, 2016 · Viewed 9.2k times · Source

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

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 .

Answer

Simon Bengtsson picture Simon Bengtsson · Aug 9, 2016

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