I'm developing in Node an application where I have an html page, which I fill in with bank data and then I need to save this page in PDF. I'm trying to use Phatom, I've tried following several tutorials, but when I pass the page URL it saves the PDF several times, it does not finish the process and always overwrites the generated PDF. What can I do to resolve this?
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));
(async function() {
const instance = await phantom.create();
const page = await instance.createPage();
await page.property('viewportSize', { width: 1920, height: 1024 });
const status = await page.open('http://localhost/gerar_diploma?id_aluno='+_id);
console.time('wait');
await timeout(500);
console.timeEnd('wait');
await page.render('docs/result.pdf');
await instance.exit();
})();