Search in sources :

Example 1 with DocumentUnderstandingServiceSettings

use of com.google.cloud.documentai.v1beta2.DocumentUnderstandingServiceSettings in project java-document-ai by googleapis.

the class SetEndPointBeta method setEndpoint.

public static void setEndpoint(String projectId, String location, String inputGcsUri) throws IOException {
    DocumentUnderstandingServiceSettings settings = DocumentUnderstandingServiceSettings.newBuilder().setEndpoint("eu-documentai.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (DocumentUnderstandingServiceClient client = DocumentUnderstandingServiceClient.create(settings)) {
        // Configure the request for processing the PDF
        String parent = String.format("projects/%s/locations/%s", projectId, location);
        GcsSource uri = GcsSource.newBuilder().setUri(inputGcsUri).build();
        // mime_type can be application/pdf, image/tiff,
        // and image/gif, or application/json
        InputConfig config = InputConfig.newBuilder().setGcsSource(uri).setMimeType("application/pdf").build();
        ProcessDocumentRequest request = ProcessDocumentRequest.newBuilder().setParent(parent).setInputConfig(config).build();
        // Recognizes text entities in the PDF document
        Document response = client.processDocument(request);
        // Get all of the document text as one big string
        String text = response.getText();
        // Process the output
        for (Document.Entity entity : response.getEntitiesList()) {
            System.out.printf("Entity text: %s\n", getText(entity, text));
            System.out.printf("Entity type: %s\n", entity.getType());
            System.out.printf("Entity mention text: %s\n", entity.getMentionText());
        }
    }
}
Also used : DocumentUnderstandingServiceClient(com.google.cloud.documentai.v1beta2.DocumentUnderstandingServiceClient) GcsSource(com.google.cloud.documentai.v1beta2.GcsSource) InputConfig(com.google.cloud.documentai.v1beta2.InputConfig) Document(com.google.cloud.documentai.v1beta2.Document) DocumentUnderstandingServiceSettings(com.google.cloud.documentai.v1beta2.DocumentUnderstandingServiceSettings) ProcessDocumentRequest(com.google.cloud.documentai.v1beta2.ProcessDocumentRequest)

Aggregations

Document (com.google.cloud.documentai.v1beta2.Document)1 DocumentUnderstandingServiceClient (com.google.cloud.documentai.v1beta2.DocumentUnderstandingServiceClient)1 DocumentUnderstandingServiceSettings (com.google.cloud.documentai.v1beta2.DocumentUnderstandingServiceSettings)1 GcsSource (com.google.cloud.documentai.v1beta2.GcsSource)1 InputConfig (com.google.cloud.documentai.v1beta2.InputConfig)1 ProcessDocumentRequest (com.google.cloud.documentai.v1beta2.ProcessDocumentRequest)1