How to align text in center using jspdf -


how align text in center using jspdf.

var doc = new jspdf(); doc.text(40, 250, 'hi how you');

if using latest version (1.1.135) api has changed text function. reads as:

api.text = function(text, x, y, flags, angle, align); 

if don't need use flags or angle though, can use:

var doc = new jspdf(); doc.text('hi how you', 40, 250, 'center'); 

keep in mind center call uses x parameter center of text string, , not left border when rendering left aligned.

link source

edit:

alternately can calculate proper x offset use text function so:

var text = "hi how you",     xoffset = (doc.internal.pagesize.width / 2) - (doc.getstringunitwidth(text) * doc.internal.getfontsize() / 2);  doc.text(text, xoffset, 250); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -