Declare new height and width for every new page on added jspdf using javascript

Viewed 291
var doc = new jsPDF('px','px', [388, 2401]); 
var width = doc.internal.pageSize.getWidth;
var height = doc.internal.pageSize.getHeight;
doc.addImage(img, 'JPEG', 0, 0, width, height);
doc.addPage();
doc.addImage(img1, 'JPEG', 0, 0, new_width, new_height); // another image 
doc.save("gg.pdf");

How can I re assign new width and height for every new image on jspdf as new jsPDF('px','px', [388, 2401]); only works for first image any way to do so that I can set new width and height for every image I add to pdf? Any suggestions would be appreciated.

1 Answers

We seem to agree that px appears to be applied as 54 per inch

// We must declare 1st page canvas before use "p", is for portrait then default units , [size x, size y] 
var doc = new jsPDF("p", "px", [388, 2401]); 
var width = doc.internal.pageSize.getWidth;
var height = doc.internal.pageSize.getHeight;
doc.addImage(img, 'JPEG', 0, 0, width, height);

// oddly the order for new page is reversed, so size, then orientation
doc.addPage([new_width, new_height], "p");
doc.addImage(img1, 'JPEG', 0, 0, new_width, new_height); // another image
 
doc.save("gg.pdf");

However always check the scaling these 2 should be same units just rotated, they report same dimension and appearance of difference is perhaps an illusion. Same file, facing pages, one pane set as MangaMode

enter image description here

Related