I'm building a Node.js application to convert PDF to PNGs and display on the user page.
The app will work like this:
- User uploads a PDF to the server
- Server converts the PDFs pages to individual PNGs
- Display PNGs on the User page
I found a great package called Node ImageMagick https://github.com/rsms/node-imagemagick but Its not a perfect fit.
Some things like -monitor
flag from ImageMagick doesn't work but doesn't work on vanilla node.js as well:
var exec = require('child_process').exec;
exec('convert -monitor myFile.pdf myFile.png', function(error, stdout, stderr) {
console.log('converting is done');
});
The thing I want to achieve is that the converting function to return the name of the files converted like: myFile-0.png, myFile-1.png.
The solution I wanted to implement was to make a directory with the name of the PDF and convert the PNGs there like:
exec('convert myFile.pdf myFile/myFile.png', function(error, stdout, stderr) {
console.log('converting is done');
});
Then read the content of that directory and send to the user the names of files and the paths.
Is this a good solution?
Can someone explain me how to achieve this goal?