6 Replies
var fs = require("fs");
var pdf2img = require('pdf-img-convert');
async function createImg() {
pdfArray = await pdf2img.convert("input/pdf2.pdf");
for (i = 0; i < pdfArray.length; i++) {
fs.writeFile("output/temp1.png", pdfArray[i], function (error) {
console.log("1");
if (error) {
console.error("Error: " + error);
}
}); //writeFile
} // for
}
// createImg();
async function f(){
await createImg();
console.log("2");
}
f();
output:
2
1
I want it to be
1
2Use fs/promises, would be way more simpler than using callback API
Any hint how to convert this code to promise, only a little bit
This thread hasn’t had any activity in 36 hours, so it’s now locked.
Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1096460083770175608