Search in sources :

Example 1 with AnalyzeDocumentRequest

use of com.amazonaws.services.textract.model.AnalyzeDocumentRequest in project aws-doc-sdk-examples by awsdocs.

the class AnalyzeDocument method main.

public static void main(String[] arg) throws Exception {
    // The S3 bucket and document
    String document = "";
    String bucket = "";
    AmazonS3 s3client = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration("https://s3.amazonaws.com", "us-east-1")).build();
    // Get the document from S3
    com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, document);
    S3ObjectInputStream inputStream = s3object.getObjectContent();
    BufferedImage image = ImageIO.read(inputStream);
    // Call AnalyzeDocument
    EndpointConfiguration endpoint = new EndpointConfiguration("https://textract.us-east-1.amazonaws.com", "us-east-1");
    AmazonTextract client = AmazonTextractClientBuilder.standard().withEndpointConfiguration(endpoint).build();
    AnalyzeDocumentRequest request = new AnalyzeDocumentRequest().withFeatureTypes("TABLES", "FORMS").withDocument(new Document().withS3Object(new S3Object().withName(document).withBucket(bucket)));
    AnalyzeDocumentResult result = client.analyzeDocument(request);
    // Create frame and panel.
    JFrame frame = new JFrame("RotateImage");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    AnalyzeDocument panel = new AnalyzeDocument(result, image);
    panel.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    frame.setContentPane(panel);
    frame.pack();
    frame.setVisible(true);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) Document(com.amazonaws.services.textract.model.Document) AmazonTextract(com.amazonaws.services.textract.AmazonTextract) BufferedImage(java.awt.image.BufferedImage) AnalyzeDocumentResult(com.amazonaws.services.textract.model.AnalyzeDocumentResult) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) S3Object(com.amazonaws.services.textract.model.S3Object) AnalyzeDocumentRequest(com.amazonaws.services.textract.model.AnalyzeDocumentRequest)

Aggregations

EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)1 AmazonTextract (com.amazonaws.services.textract.AmazonTextract)1 AnalyzeDocumentRequest (com.amazonaws.services.textract.model.AnalyzeDocumentRequest)1 AnalyzeDocumentResult (com.amazonaws.services.textract.model.AnalyzeDocumentResult)1 Document (com.amazonaws.services.textract.model.Document)1 S3Object (com.amazonaws.services.textract.model.S3Object)1 BufferedImage (java.awt.image.BufferedImage)1