最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JSPDF image can't fit and to large - Stack Overflow

programmeradmin5浏览0评论

I have a problem with my project, and it is about converting the html file to pdf. I have one question, how can we alter the size of image in jspdf because when i'm downloading the pdf, it show that the image is not fit in the page and only show half of it for A4.then, i'm trying using the A0 size but the font will bee very small even though the image is right. can some one tell how to fit the image or maybe changing the font size? (and also i'm using HTMLfromPdf.js)

I have a problem with my project, and it is about converting the html file to pdf. I have one question, how can we alter the size of image in jspdf because when i'm downloading the pdf, it show that the image is not fit in the page and only show half of it for A4.then, i'm trying using the A0 size but the font will bee very small even though the image is right. can some one tell how to fit the image or maybe changing the font size? (and also i'm using HTMLfromPdf.js)

Share Improve this question asked Apr 20, 2017 at 2:58 NexzNexz 931 silver badge10 bronze badges 2
  • Please provide a Minimal, Complete, and Verifiable example. What code have you tried? – Ricky Ruiz Commented Apr 20, 2017 at 5:51
  • @Ricky jspdf is a plugin,not my own coding. – Nexz Commented Apr 20, 2017 at 6:01
Add a ment  | 

2 Answers 2

Reset to default 5

You can resize the canvas image using the method parameters,

pdf.addImage(imgData,'JPEG',0,0,canvas.width*0.2,canvas.height*0.2,"a","FAST");

You can calculate the required ratio and replace the image width and height parameters.

You can use dimensions for jsPDF directly from canvas object like described there https://stackoverflow./a/65124814/9026103.

发布评论

评论列表(0)

  1. 暂无评论