I tried the demo, but I can’t extract any demo text from another PDF: https://www.nmlegis.gov/Sessions/22%20Regular/bills/senate/SB0014.pdf
package com.aspose.ocr.examples.OcrFeatures;
import com.aspose.ocr.DocumentRecognitionSettings;
import com.aspose.ocr.Language;
import com.aspose.ocr.RecognitionResult;
import com.aspose.ocr.RecognitionResult.LinesResult;
import com.aspose.ocr.pdf.AsposeOCRPdf;
import com.aspose.ocr.examples.Utils;
import java.awt.*;
import java.util.ArrayList;
public class OCRRecognizePdf {
public static void main(String[] args) {
// ExStart:1
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(OCRRecognizePdf.class);
// The image path
String file = dataDir + "SB0014.pdf";
// Create api instance
AsposeOCRPdf api = new AsposeOCRPdf();
// Set recognition options
DocumentRecognitionSettings settings = new DocumentRecognitionSettings(2);
settings.setLanguage(Language.Eng);
// Get result list
ArrayList<RecognitionResult> result = api.RecognizePdf(file, settings);
// print result
for(RecognitionResult r: result) {
printResult(r);
}
// ExEnd:1
System.out.println("OCRRecognizePdf: execution complete");
}
static void printResult(RecognitionResult result) {
//TEXT
System.out.println("TEXT:\n" + result.recognitionText);
//LINES
//WARNINGS
System.out.println("WARNINGS:");
for (String warning : result.warnings){
System.out.print(warning);
}
}
}