SmartOCR is a powerful OCR (Optical Character Recognition) module designed for text extraction and interaction. It enables you to extract text from PDFs and images seamlessly and even interact with links embedded in those documents.
- Text Extraction: Extract text from images and PDF files with high accuracy.
- Interactive Links: Detect and interact with clickable links in PDFs and images.
- Multi-Format Support: Compatible with a variety of image formats (e.g., PNG, JPEG) and PDF files.
- Efficient Processing: Optimized for speed and scalability in OCR operations.
Install SmartOCR via pnpm:
pnpm add klassijs-smart-ocr
Here is an example to get started with SmartOCR:
const SmartOCR = require('klassijs-smart-ocr');
(async () => {
const ocr = new SmartOCR();
// Extract text from an image
const text = await ocr.extractTextFromImage('path/to/image.jpg');
console.log('Extracted Text:', text);
// Extract text from a PDF
const pdfText = await ocr.extractTextFromPDF('path/to/document.pdf');
console.log('Extracted PDF Text:', pdfText);
// Detect and click links in an image
const links = await ocr.getLinksFromImage('path/to/image.jpg');
console.log('Detected Links:', links);
if (links.length > 0) {
const result = await ocr.clickLink(links[0]);
console.log('Link Click Result:', result);
}
})();
Extracts text from a given image.
- Parameters:
imagePath
(string): Path to the image file.
- Returns:
- (Promise) Extracted text.
Extracts text from a given PDF file.
- Parameters:
pdfPath
(string): Path to the PDF file.
- Returns:
- (Promise) Extracted text.
Detects clickable links within an image.
- Parameters:
imagePath
(string): Path to the image file.
- Returns:
- (Promise<string[]>) Array of detected links.
Detects clickable links within a PDF file.
- Parameters:
pdfPath
(string): Path to the PDF file.
- Returns:
- (Promise<string[]>) Array of detected links.
Simulates a click on the given link.
- Parameters:
link
(string): URL to interact with.
- Returns:
- (Promise) Result of the interaction.
- Node.js 14 or later
- Dependencies:
tesseract.js
(for OCR)pdf-lib
(for PDF parsing)
Contributions are welcome! If you have ideas for improvements or new features, feel free to open an issue or submit a pull request.
- Fork the repository.
- Create a new branch.
- Make your changes and commit them.
- Submit a pull request.
SmartOCR is open-source software licensed under the MIT License.
Special thanks to the developers of
tesseract.js
andpdf-lib
for making OCR and PDF processing seamless.
- (Promise) Result of the interaction.