'Node JS how to wait Dom loaded then call function?

I'm using wkhtmltopdf to print my data and I load content from json file to html. I'm trying to do, loop through the array and pass data to variable and the table take data from variable to show and save pdf then clear variable write next item in array.

When I run js file, it generates pdf for each item but same loaded on html template and pdf.

Here is my loop the data and savePDF function.

let rawdata = fs.readFileSync('data.json');
let data = JSON.parse(rawdata);

async function pdfCreate() {

  let parcaNo = data1.oemCode;
  let uygunlukItems = data1.uygunluk;
  var params = {
    parcaNo: parcaNo,
    uygunlukItem: uygunlukItems
  };
  console.log(parcaNo);

  for (var i = 0, p = Promise.resolve(); i < data.length; i++) {
    parcaNo = data[i].oemCode;
    uygunlukItems = data[i].uygunluk
    console.log(data[i].oemCode)

    p.then(saveToPdf('catalog', path.resolve(__dirname, `./PDF/${parcaNo}.pdf`), params, () => {}));
    parcaNo = "",
      uygunlukItems = [];
  }

}

await pdfCreate();

Here is my json example :

Here is my json example :

How can I create pdf for each element ?

Thanks for your help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source