26 lines
737 B
JavaScript
26 lines
737 B
JavaScript
|
|
const Tesseract = require('tesseract.js');
|
||
|
|
const path = require('path');
|
||
|
|
|
||
|
|
exports.extractPanText = async (req, res) => {
|
||
|
|
try {
|
||
|
|
if (!req.files || !req.files.pan_document) {
|
||
|
|
return res.status(400).json({ error: 'PAN document is required' });
|
||
|
|
}
|
||
|
|
const panDocPath = req.files.pan_document[0].path;
|
||
|
|
|
||
|
|
const result = await Tesseract.recognize(
|
||
|
|
panDocPath,
|
||
|
|
'eng',
|
||
|
|
{ logger: m => console.log(m) }
|
||
|
|
);
|
||
|
|
|
||
|
|
const extractedText = result.data.text;
|
||
|
|
// TODO: You can add regex here to specifically extract PAN number if needed
|
||
|
|
|
||
|
|
res.json({ extractedText });
|
||
|
|
} catch (err) {
|
||
|
|
console.error('PAN Extraction Error:', err);
|
||
|
|
res.status(500).json({ error: 'Failed to extract PAN text' });
|
||
|
|
}
|
||
|
|
};
|