javascript - jsPDF widthheight show undefined when set - Stack Overflow

I'm using jsPDF to create a PDF doc on Chrome v67, 64 bit. I've attempted to set the width an

I'm using jsPDF to create a PDF doc on Chrome v67, 64 bit. I've attempted to set the width and height of PDF document using the code below as described here:

var doc = new jsPDF("p", "mm", "a4");
var width = doc.internal.pageSize.width;
var height = doc.internal.pageSize.height;

The problem I encountered was that the width and height were not being applied. For giggles I added the following line of code after the code above:

console.log("AT#1: width=" + width + ", heigth=" + height);

only to find that the values of the width and height when I output to the console are undefined:

AT#1: width=undefined, heigth=undefined

I've searched S.O. and Google but have not found anything that suggest a possible solution or reason why they are undefined. Currently this has me stumped. Any ideas or suggestions?

I'm using jsPDF to create a PDF doc on Chrome v67, 64 bit. I've attempted to set the width and height of PDF document using the code below as described here:

var doc = new jsPDF("p", "mm", "a4");
var width = doc.internal.pageSize.width;
var height = doc.internal.pageSize.height;

The problem I encountered was that the width and height were not being applied. For giggles I added the following line of code after the code above:

console.log("AT#1: width=" + width + ", heigth=" + height);

only to find that the values of the width and height when I output to the console are undefined:

AT#1: width=undefined, heigth=undefined

I've searched S.O. and Google but have not found anything that suggest a possible solution or reason why they are undefined. Currently this has me stumped. Any ideas or suggestions?

Share Improve this question edited Jul 23, 2018 at 22:18 Rory O'Kane 30.5k11 gold badges101 silver badges133 bronze badges asked Jul 23, 2018 at 22:12 crapshootcrapshoot 832 silver badges5 bronze badges 2
  • You misspelled “height” as “heigth” in your console.log, but that shouldn't matter since it's only in the output string. The variable name after it height does seem to correctly match your declaration var height. – Rory O'Kane Commented Jul 23, 2018 at 22:20
  • Links to aid answerers: jsPDF’s documentation and source code – Rory O'Kane Commented Jul 23, 2018 at 22:22
Add a ment  | 

1 Answer 1

Reset to default 3

As this answer points out on the question How to set image to fit width of the page using jspdf? you linked, the API in later versions changed from .width and .height to .getWidth() and .getHeight().

The following code should work when you try it on jsPDF’s online demo:

var doc = new jsPDF();

var width = doc.internal.pageSize.getWidth();
var height = doc.internal.pageSize.getHeight();

console.log("AT#1: width=" + width + ", height=" + height);

What is logged:

AT#1: width=210.0015555555555, height=297.0000833333333

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

相关推荐

  • javascript - jsPDF widthheight show undefined when set - Stack Overflow

    I'm using jsPDF to create a PDF doc on Chrome v67, 64 bit. I've attempted to set the width an

    16小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信