简体   繁体   中英

How do I draw a rectangle encircling a text in jsPDF?

I am writing a text into a pdf like this:

var splitTitle = doc.splitTextToSize(str, 180);
doc.text(15, 15, splitTitle);

This is the output:

output

What I want to do is to draw a rectangle around the text. The text height can be dynamic depending on the length of the text, so how do I proceed?

Getting the text dimensions by using getTextDimensions() solved the issue:

doc.rect(15,15,doc.getTextDimensions(splitTitle).w,doc.getTextDimensions(splitTitle).h)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM