Is there any way to center text with jsPDF?

前端 未结 9 1194
半阙折子戏
半阙折子戏 2021-02-01 02:07

I\'m trying to create a simple pdf doc using javascript. I found jsPDF but I don\'t figure out how to center text. Is it possible?

9条回答
  •  后悔当初
    2021-02-01 02:50

    Do this:

    First get the page width, get half the page width and use it as the x value, use y value of your choice and pass center as the third param to center your text. Read more from documentation

    let doc = new jsPDF();
    let pageWidth = doc.internal.pageSize.getWidth();
    doc.text("My centered text",pageWidth / 2, 20, 'center');
    

提交回复
热议问题