I am trying to improve the quality of a scanned PDF to proceed to OCR. I found the command textcleaner that uses ImageMagick. So how can I include this :
textcleaner -g -e normalize -f 30 -o 12 -s 2 original.jpg output.jpg
in my Nodejs code ?
1 Answer
you can use exec:
exec(`textcleaner -g -e normalize -f 30 -o 12 -s 2 ${inputName} ${outputName}`);
or use a child process
const { spawn } = require('child_process');
const textcleaner = spawn('textcleaner', ['-g', '-e', 'normalize', '-f 30', '-o 12', '-s 2', inputName, outputName]);
textcleaner.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
2 Comments
Asma_Kh
First of all thank u but when i try your second code i get this error : Error: spawn textcleaner ENOENT . where is the problem in spawn or textcleaner ?
Constantin Guidon
hi, seems your pass an invalid file path, change
inputName
execmaybe something for you nodejs.org/api/…