How to put text inside rectangle in JsPDF

Viewed 300

Hi I am using angular 9 and as the title said, How to put text inside rectangle in JsPDF?

    pdf.rect(140, 30, 50, 25);
    pdf.setTextColor(255, 0, 0);
    pdf.text(143, 30, 'INVOICE')

here is the image

enter image description here

1 Answers

You should use the hooks for this

didDrawCell: data => {
    let textPos = data.cell.getTextPos();
    this.doc.setFillColor(255, 0, 0)
    this.doc.rect(textPos.x, textPos.y, 20, 10, 'FD')
    this.doc.text('test', textPos.x, textPos.y + 5)
}

the you adjust the x and y to be able to have your text in the rectangle. The above example is a working sample of what you want to achieve

Related