How to calculate width and height of text in jspdf?

You might want to look at the AutoTable plugin for generating tables with jsPDF. I found the built in plugin hard to work with and isn’t documented at all.

The best way I have found to calculate the width is simply doing this:

var doc = new jsPDF();
var width = doc.getTextWidth('Text');
console.log(width);

If you really need to calculate the height getDimensions() might be an option. However, it is not pixel perfect and looking at the source I doubt it will work for anything but pt. Here is an example:

var doc = new jsPDF('p', 'pt');
var dim = doc.getTextDimensions('Text');
console.log(dim); // Object {w: 24.149968818897642, h: 19.499975433070865}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)