javascript - jsPDF 2.3 Align text - Stack Overflow

I am using the latest version of jdPDF (2.3.0). In the documentation, it says that to center text, pass

I am using the latest version of jdPDF (2.3.0). In the documentation, it says that to center text, passed an object in the 4th parameter with the align: 'center' option, but that doesn't work. I also don't understand why I should specify an X if I want my text to be centered.

Here is my code :

const pdf = new window.jspdf.jsPDF();
pdf.text(`Hello world`, null, 20, { align: 'center'} );
pdf.save("TEST");

jsPDF text documentation : .html#text

I'm using jsPDF from CDN link.

I am using the latest version of jdPDF (2.3.0). In the documentation, it says that to center text, passed an object in the 4th parameter with the align: 'center' option, but that doesn't work. I also don't understand why I should specify an X if I want my text to be centered.

Here is my code :

const pdf = new window.jspdf.jsPDF();
pdf.text(`Hello world`, null, 20, { align: 'center'} );
pdf.save("TEST");

jsPDF text documentation : http://raw.githack./MrRio/jsPDF/master/docs/jsPDF.html#text

I'm using jsPDF from CDN link.

Share Improve this question asked Jan 28, 2021 at 12:40 BeweelamBeweelam 1,14612 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

(x, y) is the position on the document where the anchor point of the text is. The text alignment is relative to this point. This means to have the text centered on the document set x to the value exactly in the middle of the space (x about 105 for A4) and align: 'center'.

pdf.text(`Hello world`, pdf.internal.pageSize.getWidth() / 2, 20, { align: 'center'} );

visualized

                   (x,y)                         
                     .
                     text align left


                     .
             text align center


                     .
      text align right

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744429394a4573788.html

相关推荐

  • javascript - jsPDF 2.3 Align text - Stack Overflow

    I am using the latest version of jdPDF (2.3.0). In the documentation, it says that to center text, pass

    6天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信