When applying an angle to a text in jsPDF, it seems that the text is rotated around its left point of its baseline, while my goal is to rotate the text around its center.
This is the code that I am applying:
// Create the jsPDF instance
doc = new jsPDF({
orientation: 'p',
unit: 'mm',
format: [250, 180]
});
// Rotate the text
doc.text("Text to rotate", 80, 80, {
angle: 45
});
// Save the document
doc.save();
In the documentation, there is no property in the text()
method that allows to set the origin of the rotation as the center of the text field.
Is there a way to go around this limitation ?
2
Answers
Give this a shot. It’ll calc the center and adjust it.
You just need to add half the height of the text.