I am writing a code that allows to create a pdf file using pdfkit nodejs package, this pdf file contains images that I have in a folder on my machine but when I run it gives me an empty pdf file

var pdf = require('pdfkit');
var fs = require('fs');
var url = require('./sreenshot.js');
var myDoc = new pdf;
myDoc.pipe(fs.createWriteStream('node91.pdf'));
 // Add  images, constrain it to a given size, and center it vertically and 
horizontally

for(var i= 0; i < url.length; i++){
 const img = ['./Screenshots/capture'+ i +'.png']
 for(var j= 1; j < img.length; j++){
myDoc.image(img[0], {
  fit: [250, 300],
  align: 'center',
  valign: 'center'});
myDoc.addPage()
 .image(img[j], {
fit: [250, 300],
align: 'center',
valign: 'center'

});
}
}

myDoc.end();

0 Answers