Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set image to fit width of the page using jsPDF?

Is there any way to solve this? I tried to set width and height in mm. How can I set it to full-width?

like image 566
sreeraj nyros Avatar asked Apr 07 '16 09:04

sreeraj nyros


1 Answers

You can get the width and height of PDF document like below,

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

Then you can use this width and height for your image to fit the entire PDF document.

var imgData = 'data:image/jpeg;base64,/9j/4AAQSkZJ......';  doc.addImage(imgData, 'JPEG', 0, 0, width, height); 

Make sure that your image has the same size (resolution) of the PDF document. Otherwise it will look distorted (stretched).

If you want convert px to mm use this link http://www.endmemo.com/sconvert/millimeterpixel.php

like image 52
Purushoth Avatar answered Oct 07 '22 17:10

Purushoth