11# Cloud Document AI API C++ Client Library
22
3- :warning : This library will not be declared GA until the quickstart is operable.
4-
53This directory contains an idiomatic C++ client library for the
64[ Cloud Document AI API] [ cloud-service ] , a service that uses machine
75learning on a scalable cloud-based platform to help your organization
86efficiently scan, analyze, and understand documents.
97
10- This library is ** experimental** . Its APIs are subject to change without notice.
11-
128While this library is ** GA** , please note that the Google Cloud C++ client libraries do ** not** follow
139[ Semantic Versioning] ( https://semver.org/ ) .
1410
@@ -43,13 +39,14 @@ this library.
4339``` cc
4440#include " google/cloud/documentai/document_processor_client.h"
4541#include " google/cloud/common_options.h"
42+ #include < fstream>
4643#include < iostream>
4744#include < stdexcept>
4845
4946int main (int argc, char* argv[ ] ) try {
50- if (argc != 4 ) {
47+ if (argc != 5 ) {
5148 std::cerr << "Usage: " << argv[ 0]
52- << " project-id location-id processor-id\n";
49+ << " project-id location-id processor-id filename (PDF only) \n";
5350 return 1;
5451 }
5552 std::string const location = argv[ 2] ;
@@ -59,11 +56,11 @@ int main(int argc, char* argv[]) try {
5956 }
6057
6158 namespace gc = ::google::cloud;
59+ namespace documentai = ::google::cloud : :documentai;
60+ // The Document AI service requires using an endpoint matching the processor's
61+ // location.
6262 auto options = gc::Options{}.set< gc::EndpointOption > (
6363 location + "-documentai.googleapis.com");
64- options.set< google::cloud::TracingComponentsOption > ({"rpc"});
65-
66- namespace documentai = ::google::cloud : :documentai;
6764 auto client = documentai::DocumentProcessorServiceClient(
6865 documentai::MakeDocumentProcessorServiceConnection(options));
6966
@@ -73,9 +70,10 @@ int main(int argc, char* argv[]) try {
7370 google::cloud : :documentai::v1::ProcessRequest req;
7471 req.set_name(resource);
7572 req.set_skip_human_review(true);
76- auto& doc = * req.mutable_inline_document ();
73+ auto& doc = * req.mutable_raw_document ();
7774 doc.set_mime_type("application/pdf");
78- doc.set_uri("gs://cloud-samples-data/documentai/invoice.pdf");
75+ std::ifstream is(argv[ 4] );
76+ doc.set_content(std::string{std::istreambuf_iterator<char >(is), {}});
7977
8078 auto resp = client.ProcessDocument(std::move(req));
8179 if (!resp) throw std::runtime_error(resp.status().message());
0 commit comments