use of software.amazon.awssdk.services.textract.model.AnalyzeDocumentRequest in project aws-doc-sdk-examples by awsdocs.
the class AnalyzeDocument method analyzeDoc.
// snippet-start:[textract.java2._analyze_doc.main]
public static void analyzeDoc(TextractClient textractClient, String sourceDoc) {
try {
InputStream sourceStream = new FileInputStream(new File(sourceDoc));
SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
// Get the input Document object as bytes
Document myDoc = Document.builder().bytes(sourceBytes).build();
List<FeatureType> featureTypes = new ArrayList<FeatureType>();
featureTypes.add(FeatureType.FORMS);
featureTypes.add(FeatureType.TABLES);
AnalyzeDocumentRequest analyzeDocumentRequest = AnalyzeDocumentRequest.builder().featureTypes(featureTypes).document(myDoc).build();
AnalyzeDocumentResponse analyzeDocument = textractClient.analyzeDocument(analyzeDocumentRequest);
List<Block> docInfo = analyzeDocument.blocks();
Iterator<Block> blockIterator = docInfo.iterator();
while (blockIterator.hasNext()) {
Block block = blockIterator.next();
System.out.println("The block type is " + block.blockType().toString());
}
} catch (TextractException | FileNotFoundException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.textract.model.AnalyzeDocumentRequest in project aws-doc-sdk-examples by awsdocs.
the class TextractService method analyzeDoc.
public String analyzeDoc(byte[] bytes) {
List myList = new ArrayList<String>();
try {
Region region = Region.US_EAST_2;
TextractClient textractClient = TextractClient.builder().region(region).build();
SdkBytes sourceBytes = SdkBytes.fromByteArray(bytes);
// Get the input Document object as bytes
Document myDoc = Document.builder().bytes(sourceBytes).build();
List<FeatureType> featureTypes = new ArrayList<FeatureType>();
featureTypes.add(FeatureType.FORMS);
featureTypes.add(FeatureType.TABLES);
AnalyzeDocumentRequest analyzeDocumentRequest = AnalyzeDocumentRequest.builder().featureTypes(featureTypes).document(myDoc).build();
AnalyzeDocumentResponse analyzeDocument = textractClient.analyzeDocument(analyzeDocumentRequest);
List<Block> docInfo = analyzeDocument.blocks();
Iterator<Block> blockIterator = docInfo.iterator();
while (blockIterator.hasNext()) {
Block block = blockIterator.next();
myList.add("The block type is " + block.blockType().toString());
}
return convertToString(toXml(myList));
} catch (TextractException e) {
System.err.println(e.getMessage());
System.exit(1);
}
return "";
}
Aggregations