Vive
Vive

Reputation: 208

How to get percentage of node js proccess?

Currently, I used this library https://github.com/mooz/node-pdf-image/ for convert PDF to an image.

When I convert PDF that has more than 50 pages, I want to know how many percentages of convert has been done or check which page that on processing.

Is that any possibility to doing that? or any library that can check percentages of node process?

Thank you.

Upvotes: 0

Views: 455

Answers (1)

generalhenry
generalhenry

Reputation: 17319

node-pdf-image supports converting the pages one by one so you just need to emit events as they progress. You can then display the events with console.log, or send them to the browser with websockets etc . . .

async function convertWithProgress(eventEmitter, pdf) {
  const numberOfPages = await pdf.numberOfPages();
  for (let page = 0; page < numberOfPages; page++) {
    eventEmitter.emit('progress', page / numberOfPages);
    await pdf.convertPage(page);
  }
  eventEmitter.emit('progress', 1);
  // combine images?
  // send images?
}

Upvotes: 1

Related Questions