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());
}
}
}
Aggregations