pdf-decomposer
Version:
📚 Extract text and images (as buffers) from PDF files using native parsing and OCR with Tesseract.
24 lines (23 loc) • 830 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const child_process_1 = require("child_process");
function extractTextFromPdf(pdfPath) {
return new Promise((resolve, reject) => {
const pdftotext = (0, child_process_1.spawn)('pdftotext', ['-layout', pdfPath, '-']);
let output = '';
pdftotext.stdout.on('data', (data) => {
output += data.toString();
});
pdftotext.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
pdftotext.on('close', (code) => {
if (code === 0)
resolve(output);
else
reject(new Error(`pdftotext exited with code ${code}`));
});
});
}
// Exemple d’utilisation
extractTextFromPdf('sample.pdf').then(console.log);