I'm using Spire.OCR 1.9.2 version to extract data from a scanned image.
I could not get any data from the scanned image. I used the below code,
- Code: Select all
// Create an OcrScanner object
OcrScanner scanner = new OcrScanner();
// Set the dependency file path for the OcrScanner object
scanner.setDependencies(dependencies);
// Use the OcrScanner object to scan the specified image file
scanner.scan(FILE_PATH);
// Get the scanned text content
String scannedText = scanner.getText().toString();
// Create an output file object
File output = new File(OUTPUT_FILE_PATH);
// If the output file already exists, delete it
if (output.exists()) {
output.delete();
}
// Create a BufferedWriter object to write content to the output file
BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE_PATH));
// Write the scanned text content to the output file
writer.write(scannedText);
// Close the BufferedWriter object to release resources
writer.close();
I have converted the scanned image content into a PDF file using Spire products like the one below.
- Code: Select all
// Create a PDF document
PdfDocument pdf = new PdfDocument();
// Add a new page
PdfPageBase page = pdf.getPages().add();
// Load the image
PdfImage image = PdfImage.fromFile(FILE_PATH);
double widthFitRate = image.getPhysicalDimension().getWidth() / page.getCanvas().getClientSize().getWidth();
double heightFitRate = image.getPhysicalDimension().getHeight() / page.getCanvas().getClientSize().getHeight();
double fitRate = Math.max(widthFitRate, heightFitRate);
// get the picture width and height
double fitWidth = image.getPhysicalDimension().getWidth() / fitRate;
double fitHeight = image.getPhysicalDimension().getHeight() / fitRate;
// Draw image
page.getCanvas().drawImage(image, 0, 30, fitWidth, fitHeight);
// Save document to file
pdf.saveToFile(OUTPUT_FILE_PATH);
pdf.close();
After converting the image into a PDF file, I tried to scan the data from this PDF file. In this, the table has solid lines. But no table has been identified.
Please guide how can I extract scanned content.