Search code examples
javascriptjspdf

jsPDF overlapping dynamic


I am trying to use user generated in a PDF. I do not know how to prevent the next text from overlapping.

var doc = new jsPDF("p", "pt", "a4", true});

doc.text("long string that can be too long rorem ipsum", data.settings.margin.left + 15, 22, { { align: "right", maxWidth: 210 } });

doc.text("some more text", data.settings.margin.left + 15, 32);

I know how to make it work using autoTable, but not without


Solution

  • I tried to make it.

    const pirnt = "long string that can be too long rorem ipsum"
    doc.text(pirnt, data.settings.margin.left + 15, 22, { { align: "right", maxWidth: 210 } });
    let long = doc.getTextWidth(pirnt);
    let infit = (Math.ceil(long / 210) - 1);
    

    This may not be the best solution, but does the job, barely.