I am using jsPDF in a project and mostly have things working as expected. If, however, I decide to change the default character spacing to any non-zero value, centering gets thrown off by the character spacing and text eventually bleeds off the right edge of the page if the value is set high enough. Is there any way to get the alignment property working properly with setCharSpace that I’m missing? If not, is there some way to construct a calculation that accounts for the character spacing?
const lineHeight = 1.35;
const doc = new jsPDF({
unit: "mm",
lineHeight: lineHeight,
});
const margin = 24;
const fontSize = 10;
const pageWidth = Math.round(doc.internal.pageSize.width);
const pageHeight = Math.round(doc.internal.pageSize.height);
const maxLineWidth = pageWidth - 2 * margin;
const charSpace = 0.3; // Default = 0
const para = 'This is my repeating text. '.repeat(100);
let textLines = doc
.setFont("Helvetica", "normal") //
.setFontSize(fontSize)
.setCharSpace(charSpace)
.splitTextToSize(para, maxLineWidth);