Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 .

like image 457
Saravana Kumar Avatar asked Oct 27 '25 10:10

Saravana Kumar


1 Answers

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);
like image 133
Simon Bengtsson Avatar answered Oct 29 '25 05:10

Simon Bengtsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!